

``` r
#INTRO: LOADING PACKAGES ETC----
library(foreign)
library(reshape2)
library(data.table)
library(stargazer)
library(MatchIt)
#library(nonrandom)
library(ggplot2)
#library(gdata1)
library(gmodels)
library(gridExtra)
library(haven)
library(plyr)
#library(car)
#library(xlsx)
library(tidyr)
library(reshape)
library(countrycode)
#library(dGlyr)
library(readr)
library(gnm)
library(MNP)
library(nls2)
library(nlstools)
library(stats)
library(dplyr)
library(matrixStats)
library(miceadds)
library(minpack.lm)
library(lfe)
library(lubridate)
library(AER)
library(reshape)
library(reshape2)
library(tictoc)
library(xtable)
library(Formula)
library(mlogit)
library(plm)
library(survival)
library(plotly)
library(alpaca)
library(lmtest)
library(sandwich)
# library(mnlogit)

library(foreach)#parallel foreach
library(iterators)
library(parallel)
library(doParallel)

library(msm)
library(tikzDevice)

library(ggpubr)#combine ggplot graphs together
```

```
## 
## Attaching package: 'ggpubr'
```

```
## The following object is masked from 'package:plyr':
## 
##     mutate
```

``` r
library(estimatr)#lm_robust

library(clubSandwich)#coef_test
```

```
## Registered S3 method overwritten by 'clubSandwich':
##   method    from    
##   bread.mlm sandwich
```

``` r
library(sjlabelled)#labelled variables (set_labels)
```

```
## 
## Attaching package: 'sjlabelled'
```

```
## The following objects are masked from 'package:labelled':
## 
##     copy_labels, remove_labels, to_character, to_factor, val_labels
```

```
## The following object is masked from 'package:forcats':
## 
##     as_factor
```

```
## The following object is masked from 'package:dplyr':
## 
##     as_label
```

```
## The following objects are masked from 'package:haven':
## 
##     as_factor, read_sas, read_spss, read_stata, write_sas, zap_labels
```

```
## The following object is masked from 'package:ggplot2':
## 
##     as_label
```

``` r
library(openxlsx)#read.xlsx

library(labelled)#change labels to columns

library(texreg)#extract for lm.cluster
```

```
## Version:  1.39.3
## Date:     2023-11-09
## Author:   Philip Leifeld (University of Essex)
## 
## Consider submitting praise using the praise or praise_interactive functions.
## Please cite the JSS article in your publications -- see citation("texreg").
```

```
## 
## Attaching package: 'texreg'
```

```
## The following object is masked from 'package:tidyr':
## 
##     extract
```

``` r
options(width=2000)#set max characters shown
options(max.print=200000)#set max rows shown console

# !diagnostics suppress=Dsvr,Dgdm

rm(list=ls())
cat("\014")
```



``` r
#READ DATA:----
load("d29.RData")
```

```
## Warning in readChar(con, 5L, useBytes = TRUE): cannot open compressed file 'd29.RData', probable reason 'No such file or directory'
```

```
## Error in readChar(con, 5L, useBytes = TRUE): cannot open the connection
```

``` r
#ASSIGN WEIGHTS:----

#assign Weight Country:
#calculate country (weighted by country population) weights:
# de = de %>% group_by(Es) %>% mutate(Resp = n()/6 )#number of respondent by Es
de$Pop=NA#country population in millions
```

```
## Error in de$Pop = NA: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="AUS"]=25
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="AUT"]=9
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="CAN"]=37
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="DEU"]=68#West Germany (84 All Germany)
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="DNK"]=6
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="ESP"]=47
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="FIN"]=6
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="GBR"]=61
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="GRC"]=10
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="IRL"]=5
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="ISL"]=1
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="ISR"]=9
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="ITA"]=61
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="NLD"]=17
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="NOR"]=5
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="NZL"]=5
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="PRT"]=10
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Pop[de$Ec=="SWE"]=10
```

```
## Error in `*tmp*`$Pop: object of type 'closure' is not subsettable
```

``` r
de$Rwp=de$Pop#Respondent Weight Country
```

```
## Error in de$Pop: object of type 'closure' is not subsettable
```

``` r
de$Rwp=de$Rwp/mean(de$Rwp)#set mean weight == 1
```

```
## Error in de$Rwp: object of type 'closure' is not subsettable
```

``` r
#calculate country weights (weights s.t. all elections same number of respondents):
de = de %>% group_by(Es) %>% mutate(Resp = n()/6 )#number of respondent by Es
```

```
## Error in UseMethod("group_by"): no applicable method for 'group_by' applied to an object of class "function"
```

``` r
de$Rwc=1000/de$Resp#Respondent Weight Country
```

```
## Error in de$Resp: object of type 'closure' is not subsettable
```

``` r
de$Rwc=de$Rwc/mean(de$Rwc)#set mean weight == 1
```

```
## Error in de$Rwc: object of type 'closure' is not subsettable
```

``` r
summary(de$Rwc)
```

```
## Error in (function (cond) : error in evaluating the argument 'object' in selecting a method for function 'summary': object of type 'closure' is not subsettable
```

``` r
#set demographic weights to average 1 by election:
# (since I deleted respondents w/o Va,Pl,Ll, they unbalance the weights for that election
# in a way that is election specific, in this way I reset sum weghts to be 1 by election)
de = de %>% group_by(Es) %>% mutate(Rwd=Rwd/mean(Rwd))
```

```
## Error in UseMethod("group_by"): no applicable method for 'group_by' applied to an object of class "function"
```

``` r
summary(de$Rwd)
```

```
## Error in (function (cond) : error in evaluating the argument 'object' in selecting a method for function 'summary': object of type 'closure' is not subsettable
```

``` r
#calculate country demographic weights:
# NB: this is equivalent to CSES Dataset Weight:
# | The derivative "Dataset Weight" (D1014) has been created so
# | that each election study in the dataset will contribute
# | equally to analyses of respondents, regardless of the number
# | of interviews in each election study.
de$Rwcd=de$Rwc*de$Rwd#Respondent Weight Country and Demographic
```

```
## Error in de$Rwc: object of type 'closure' is not subsettable
```

``` r
de$Rwcd=de$Rwcd/mean(de$Rwcd,na.rm=T)#set mean weight == 1
```

```
## Error in de$Rwcd: object of type 'closure' is not subsettable
```

``` r
summary(de$Rwcd)
```

```
## Error in (function (cond) : error in evaluating the argument 'object' in selecting a method for function 'summary': object of type 'closure' is not subsettable
```

``` r
max(de$Rwcd)/min(de$Rwcd)
```

```
## Error in de$Rwcd: object of type 'closure' is not subsettable
```

``` r
de$Rwcp=de$Rwc*de$Rwp
```

```
## Error in de$Rwc: object of type 'closure' is not subsettable
```

``` r
de$Rwcp=de$Rwcp/mean(de$Rwcp,na.rm=T)#set mean weight == 1
```

```
## Error in de$Rwcp: object of type 'closure' is not subsettable
```

``` r
de$Rwcdp=de$Rwc*de$Rwd*de$Rwp
```

```
## Error in de$Rwc: object of type 'closure' is not subsettable
```

``` r
de$Rwcdp=de$Rwcdp/mean(de$Rwcdp,na.rm=T)#set mean weight == 1
```

```
## Error in de$Rwcdp: object of type 'closure' is not subsettable
```

``` r
de=de[,-which(names(de) %in% c("Resp","Pop"))]#remove working columns
```

```
## Error in de[, -which(names(de) %in% c("Resp", "Pop"))]: object of type 'closure' is not subsettable
```

``` r
#CALCULATE Pl,Ll BY ELECTION:----
reg=de %>% group_by(Es) %>% summarise(mod = list(summary(clogit(Va ~ Pl+Ll +strata(Esalt), robust=T, weights=Rwcd, method="efron"))$coefficients[,1]))#create Pl and Ll by Es
```

```
## Error in UseMethod("group_by"): no applicable method for 'group_by' applied to an object of class "function"
```

``` r
length(unlist(reg))#366
```

```
## Error in eval(expr, envir, enclos): object 'reg' not found
```

``` r
Es=unlist(reg)[1:122]
```

```
## Error in eval(expr, envir, enclos): object 'reg' not found
```

``` r
Pl=unlist(reg)[123:366]
```

```
## Error in eval(expr, envir, enclos): object 'reg' not found
```

``` r
Pl=Pl[seq(1,244,2)]
```

```
## Error in eval(expr, envir, enclos): object 'Pl' not found
```

``` r
Ll=unlist(reg)[123:366]
```

```
## Error in eval(expr, envir, enclos): object 'reg' not found
```

``` r
Ll=Ll[seq(2,244,2)]
```

```
## Error in eval(expr, envir, enclos): object 'Ll' not found
```

``` r
ds=data.frame(Es,Pl,Ll)
```

```
## Error in eval(expr, envir, enclos): object 'Es' not found
```

``` r
ds$Pl=as.numeric(as.character(ds$Pl))
```

```
## Error in eval(expr, envir, enclos): object 'ds' not found
```

``` r
ds$Ll=as.numeric(as.character(ds$Ll))
```

```
## Error in eval(expr, envir, enclos): object 'ds' not found
```

``` r
ds$PlLl=ds$Pl-ds$Ll
```

```
## Error in eval(expr, envir, enclos): object 'ds' not found
```

``` r
ds$Ey=substr(ds$Es,5,8)
```

```
## Error in eval(expr, envir, enclos): object 'ds' not found
```

``` r
ds$Ey=as.numeric(ds$Ey)
```

```
## Error in eval(expr, envir, enclos): object 'ds' not found
```

``` r
ds$Ec=substr(ds$Es,1,3)#
```

```
## Error in eval(expr, envir, enclos): object 'ds' not found
```

``` r
ds$time=ds$Ey-1960
```

```
## Error in eval(expr, envir, enclos): object 'ds' not found
```

``` r
rm(reg,Es,Pl,Ll)
```

```
## Warning in rm(reg, Es, Pl, Ll): object 'reg' not found
```

```
## Warning in rm(reg, Es, Pl, Ll): object 'Es' not found
```

```
## Warning in rm(reg, Es, Pl, Ll): object 'Pl' not found
```

```
## Warning in rm(reg, Es, Pl, Ll): object 'Ll' not found
```

``` r
#merge Ed:
dss=de[,c(3,4)]
```

```
## Error in de[, c(3, 4)]: object of type 'closure' is not subsettable
```

``` r
dss=dss %>% group_by(Es) %>% filter(row_number (Es) == 1)
```

```
## Error in eval(expr, envir, enclos): object 'dss' not found
```

``` r
ds=merge(ds,dss,by="Es")
```

```
## Error in eval(expr, envir, enclos): object 'ds' not found
```

``` r
ds$Ed=as.factor(ds$Ed)#(for graphs)
```

```
## Error in eval(expr, envir, enclos): object 'ds' not found
```

``` r
#merge NP:
dss=de[,c(3,7)]
```

```
## Error in de[, c(3, 7)]: object of type 'closure' is not subsettable
```

``` r
dss=dss %>% group_by(Es) %>% filter(row_number (Es) == 1)
```

```
## Error in eval(expr, envir, enclos): object 'dss' not found
```

``` r
ds=merge(ds,dss,by="Es")
```

```
## Error in eval(expr, envir, enclos): object 'ds' not found
```

``` r
ds$NP=as.factor(ds$NP)#(for graphs)
```

```
## Error in eval(expr, envir, enclos): object 'ds' not found
```

``` r
#BASE FOR COUNTRY SLOPE FE:----
#Ec:Pl FE:
for (i1 in 1:length(sort(unique(de$Ec)))) {#creating dummy variables Ec:Pl (for FE)
  de[[paste0("Pl_",sort(unique(de$Ec))[i1])]]=ifelse(de$Ec==sort(unique(de$Ec))[i1],de$Pl,0)#de$Pl
}
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
#Ec:Ll FE:
for (i1 in 1:length(sort(unique(de$Ec)))) {#creating dummy variables Ec:Ll (for FE)
  de[[paste0("Ll_",sort(unique(de$Ec))[i1])]]=ifelse(de$Ec==sort(unique(de$Ec))[i1],de$Ll,0)#de$Ll
}
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
#create text for regression function:
txt=""
for (i1 in 1:length(sort(unique(de$Ec)))) {#creating function text for dummy variables Es:alt except for alt=1
  txt=paste(txt,paste0("Pl_",sort(unique(de$Ec))[i1]),sep="+")
  txt=paste(txt,paste0("Ll_",sort(unique(de$Ec))[i1]),sep="+")
}
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
#BASE FOR DENSITY PLOTS:----

#create dataset density all data:
dyALL = de[!is.na(de$Va)&!is.na(de$Pl)&!is.na(de$Ll),] %>% 
  group_by(Ey) %>% mutate(Eyn=n())#number of obs by Ey
```

```
## Error in de$Va: object of type 'closure' is not subsettable
```

``` r
dyALL$Eyn=dyALL$Eyn/nrow(de)#density by Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
dyALL=dyALL %>% group_by(Ey) %>% filter(row_number()==1)#keep only 1 obs per Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
#create dataset density data with left-right self reported position:
dyLRR = de[!is.na(de$LRR)&!is.na(de$Va)&!is.na(de$Pl)&!is.na(de$Ll),] %>% 
  group_by(Ey) %>% mutate(Eyn=n())#number of obs by Ey
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
dyLRR$Eyn=dyLRR$Eyn/nrow(de)#density by Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyLRR' not found
```

``` r
dyLRR=dyLRR %>% group_by(Ey) %>% filter(row_number()==1)#keep only 1 obs per Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyLRR' not found
```

``` r
#create dataset density data with left-right distance voter-party:
dyLRD = de[!is.na(de$LRD)&!is.na(de$Va)&!is.na(de$Pl)&!is.na(de$Ll),] %>% 
  group_by(Ey) %>% mutate(Eyn=n())#number of obs by Ey
```

```
## Error in de$LRD: object of type 'closure' is not subsettable
```

``` r
dyLRD$Eyn=dyLRD$Eyn/nrow(de)#density by Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyLRD' not found
```

``` r
dyLRD=dyLRD %>% group_by(Ey) %>% filter(row_number()==1)#keep only 1 obs per Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyLRD' not found
```

``` r
#create dataset density data only countries observed before 1990:
dy90 = de[(de$Ec %in% c("CAN","DEU","DNK","ESP","GBR","GRC","ISL","NLD","NOR","SWE")),] %>% 
  group_by(Ey) %>% mutate(Eyn=n())#number of obs by Ey
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
dy90$Eyn=dy90$Eyn/nrow(de)#density by Ey
```

```
## Error in eval(expr, envir, enclos): object 'dy90' not found
```

``` r
dy90=dy90 %>% group_by(Ey) %>% filter(row_number()==1)#keep only 1 obs per Ey
```

```
## Error in eval(expr, envir, enclos): object 'dy90' not found
```

``` r
#SUMMARY STATISTICS:----

#list of lelections by country and data source:
table(de$Es,de$Ed)
```

```
## Error in de$Es: object of type 'closure' is not subsettable
```

``` r
#data:
length(unique(de$chid))#number of observations (individuals): 170048
```

```
## Error in de$chid: object of type 'closure' is not subsettable
```

``` r
length(unique(de$Esalt))#number of election-choices: 732
```

```
## Error in de$Esalt: object of type 'closure' is not subsettable
```

``` r
length(unique(de$Ec))#number of countries: 18
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
length(unique(de$Es))#number of elections: 122
```

```
## Error in de$Es: object of type 'closure' is not subsettable
```

``` r
#Pl,Ll:
median(de$Pl,na.rm = T)#median party likability chosen alterntive: 5
```

```
## Error in de$Pl: object of type 'closure' is not subsettable
```

``` r
sd(de$Pl,na.rm = T)#standard deviation party likability chosen alterntive: 2.97
```

```
## Error in de$Pl: object of type 'closure' is not subsettable
```

``` r
median(de$Ll,na.rm = T)#median leader likability chosen alterntive: 5
```

```
## Error in de$Ll: object of type 'closure' is not subsettable
```

``` r
sd(de$Ll,na.rm = T)#standard deviation leader likability chosen alterntive: 2.95
```

```
## Error in de$Ll: object of type 'closure' is not subsettable
```

``` r
median(de$Pl[de$Va==1],na.rm = T)#median party likability chosen alterntive: 8
```

```
## Error in de$Pl: object of type 'closure' is not subsettable
```

``` r
sd(de$Pl[de$Va==1],na.rm = T)#standard deviation party likability chosen alterntive: 1.852487
```

```
## Error in de$Pl: object of type 'closure' is not subsettable
```

``` r
median(de$Ll[de$Va==1],na.rm = T)#median leader likability chosen alterntive: 8
```

```
## Error in de$Ll: object of type 'closure' is not subsettable
```

``` r
sd(de$Ll[de$Va==1],na.rm = T)#standard deviation leader likability chosen alterntive: 2.074604
```

```
## Error in de$Ll: object of type 'closure' is not subsettable
```

``` r
##average Pl,Ll effect (with no time trend):
#Z-test functions:
Ztestfun_base=function(CLC){
  m=CLC$coefficients[paste0("Pl")]-CLC$coefficients[paste0("Ll")]#mean
  v=vcov(CLC)[paste0("Pl"),paste0("Pl")]+vcov(CLC)[paste0("Ll"),paste0("Ll")]-
    2*vcov(CLC)[paste0("Pl"),paste0("Ll")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
#regression:
CLC_base=clogit(Va ~ Pl+Ll
                +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl + Ll + Pl_AUS + Ll_AUS + : 'data' must be a data.frame, environment, or list
```

``` r
#significance difference Pl-Ll coefficients:
Ztestfun_base(CLC_base)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_base' not found
```

``` r
#difference in odds between Pl and Ll:
summary(CLC_base)$coefficients[1,2]/summary(CLC_base)$coefficients[2,2]
```

```
## Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'summary': object 'CLC_base' not found
```

``` r
##MEASURE LEADER LIKABILITY, PARTY LIKABILITY, PARTY IDENTIFICATION:----

#code Pi=0 and not NA in Es where it was asked:
de = de %>%
  mutate(Pi = as.numeric(as.character(Pi))) %>%
  group_by(Es) %>%
  mutate(Pit = ifelse(any(!is.na(Pi)), 1, 0))
```

```
## Error in UseMethod("mutate"): no applicable method for 'mutate' applied to an object of class "function"
```

``` r
de$Pi[de$Pit==1&is.na(de$Pi)]=0
```

```
## Error in `*tmp*`$Pi: object of type 'closure' is not subsettable
```

``` r
de = de %>% select(-Pit)
```

```
## Error in UseMethod("select"): no applicable method for 'select' applied to an object of class "function"
```

``` r
#create dataset density data with Pi:
dyPi = de[!is.na(de$Va)&!is.na(de$Pl)&!is.na(de$Ll)&!is.na(de$Pi),] %>% 
  group_by(Ey) %>% mutate(Eyn=n())#number of obs by Ey
```

```
## Error in de$Va: object of type 'closure' is not subsettable
```

``` r
dyPi$Eyn=dyPi$Eyn/nrow(de)#density by Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyPi' not found
```

``` r
dyPi=dyPi %>% group_by(Ey) %>% filter(row_number()==1)#keep only 1 obs per Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyPi' not found
```

``` r
##Pl ON Ll:----
#confidence interval functions:
CI.Ll_Pl10fun=function(CLC,t0,pe){
  CI.Ll=matrix(NA,nrow=59,ncol=4)
  for (t in 1:59) {
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.Ll[t,1]=CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6#fitted values
    CI.Ll[t,2]=1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]+
      2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]+
      2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]+
      2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]+
      2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]+
      2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]#Variance
    CI.Ll[t,3]=CI.Ll[t,1]-qnorm(0.975)*sqrt(CI.Ll[t,2])#95% CI lower
    CI.Ll[t,4]=CI.Ll[t,1]+qnorm(0.975)*sqrt(CI.Ll[t,2])#95% CI upper
  }
  CI.Ll=as.data.frame(CI.Ll)
  CI.Ll$t=c(1961:2019)
  if (pe==1) {CI.Ll=CI.Ll[1:(10+t0),]}
  if (pe==2) {CI.Ll=CI.Ll[(11+t0):(20+t0),]}
  if (pe==3) {CI.Ll=CI.Ll[(21+t0):(30+t0),]}
  if (pe==4) {CI.Ll=CI.Ll[(31+t0):(40+t0),]}
  if (pe==5) {CI.Ll=CI.Ll[(41+t0):(50+t0),]}
  if (pe==6) {CI.Ll=CI.Ll[(51+t0):59,]}
  CI.Ll
}

#Z-test functions:
ZtestfunLl=function(CLC,per1,per2){
  m=CLC$coefficients[paste0("Ll:time",per2)]-CLC$coefficients[paste0("Ll:time",per1)]#mean
  v=vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]-
    vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}

#time variables:
t0=0#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
LMR_Ll_Pl_0=lm_robust(Pl ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
                      +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
                      , cluster=Ec, data=de, se_type="stata")#regression
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LR_Ll_Pl_0=lm(Pl ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
                      +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
                      , data=de, se_type="stata")#regression
```

```
## Error in model.frame.default(formula = Pl ~ Ll:time2 + Ll:time3 + Ll:time4 + : 'data' must be a data.frame, environment, or list
```

``` r
##Table 1## Party Likability on Leader Likability
#table (hypothesis testing):
LMR_Ll_Pl_0$r.squared
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_0' not found
```

``` r
LMR_Ll_Pl_0$nobs
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_0' not found
```

``` r
c(LMR_Ll_Pl_0$coefficients["Ll:time2"],LMR_Ll_Pl_0$std.error["Ll:time2"],LMR_Ll_Pl_0$p.value["Ll:time2"])#t2-t1=Ll:time2
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_0' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_0,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_0' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_0' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_0' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_0' not found
```

``` r
#plots:
# tikz(paste0("plot_Pl_Ll_0.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Party Likability on Leader Likability") +xlab("Year") +ylab("estimated coefficient") + 
        coord_cartesian(ylim=c(0.66,0.84)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.84-0.66)+0.66))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_0,0,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_0,0,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_0,0,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_0,0,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_0,0,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_0,0,6)) )
```

```
## Warning: The `size` argument of `element_rect()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
```

```
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##Table D1##
##starting value for thresholds -4
#time variables:
t0=-4#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
LMR_Ll_Pl_m4=lm_robust(Pl ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
                      +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
                      , cluster=Ec, data=de, se_type="stata")#regression
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LR_Ll_Pl_m4=lm(Pl ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
              +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
              , data=de, se_type="stata")#regression
```

```
## Error in model.frame.default(formula = Pl ~ Ll:time2 + Ll:time3 + Ll:time4 + : 'data' must be a data.frame, environment, or list
```

``` r
#table (hypothesis testing):
LMR_Ll_Pl_m4$r.squared
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_m4' not found
```

``` r
LMR_Ll_Pl_m4$nobs
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_m4' not found
```

``` r
c(LMR_Ll_Pl_m4$coefficients["Ll:time2"],LMR_Ll_Pl_m4$std.error["Ll:time2"],LMR_Ll_Pl_m4$p.value["Ll:time2"])#t2-t1=Ll:time2
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_m4' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_m4,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_m4' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_m4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_m4' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_m4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_m4' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_m4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_m4' not found
```

``` r
#plots:
# tikz(paste0("plot_Pl_Ll_m4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Party Likability on Leader Likability") +xlab("Year") +ylab("estimated coefficient") + 
        coord_cartesian(ylim=c(0.66,0.84)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.84-0.66)+0.66))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_m4,-4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_m4,-4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_m4,-4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_m4,-4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_m4,-4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_m4,-4,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##starting value for thresholds -2
#time variables:
t0=-2#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
LMR_Ll_Pl_m2=lm_robust(Pl ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
                       +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
                       , cluster=Ec, data=de, se_type="stata")#regression
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LR_Ll_Pl_m2=lm(Pl ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
               +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
               , data=de, se_type="stata")#regression
```

```
## Error in model.frame.default(formula = Pl ~ Ll:time2 + Ll:time3 + Ll:time4 + : 'data' must be a data.frame, environment, or list
```

``` r
#table (hypothesis testing):
LMR_Ll_Pl_m2$r.squared
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_m2' not found
```

``` r
LMR_Ll_Pl_m2$nobs
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_m2' not found
```

``` r
c(LMR_Ll_Pl_m2$coefficients["Ll:time2"],LMR_Ll_Pl_m2$std.error["Ll:time2"],LMR_Ll_Pl_m2$p.value["Ll:time2"])#t2-t1=Ll:time2
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_m2' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_m2,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_m2' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_m2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_m2' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_m2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_m2' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_m2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_m2' not found
```

``` r
#plots:
# tikz(paste0("plot_Pl_Ll_m2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Party Likability on Leader Likability") +xlab("Year") +ylab("estimated coefficient") + 
        coord_cartesian(ylim=c(0.66,0.84)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.84-0.66)+0.66))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_m2,-2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_m2,-2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_m2,-2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_m2,-2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_m2,-2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_m2,-2,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##starting value for thresholds 2
#time variables:
t0=2#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
LMR_Ll_Pl_2=lm_robust(Pl ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
                       +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
                       , cluster=Ec, data=de, se_type="stata")#regression
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LR_Ll_Pl_2=lm(Pl ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
               +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
               , data=de, se_type="stata")#regression
```

```
## Error in model.frame.default(formula = Pl ~ Ll:time2 + Ll:time3 + Ll:time4 + : 'data' must be a data.frame, environment, or list
```

``` r
#table (hypothesis testing):
LMR_Ll_Pl_2$r.squared
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_2' not found
```

``` r
LMR_Ll_Pl_2$nobs
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_2' not found
```

``` r
c(LMR_Ll_Pl_2$coefficients["Ll:time2"],LMR_Ll_Pl_2$std.error["Ll:time2"],LMR_Ll_Pl_2$p.value["Ll:time2"])#t2-t1=Ll:time2
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_2' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_2,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_2' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_2' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_2' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_2' not found
```

``` r
#plots:
# tikz(paste0("plot_Pl_Ll_2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Party Likability on Leader Likability") +xlab("Year") +ylab("estimated coefficient") + 
        coord_cartesian(ylim=c(0.66,0.84)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.84-0.66)+0.66))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_2,2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_2,2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_2,2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_2,2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_2,2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_2,2,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##starting value for thresholds 4
#time variables:
t0=4#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
LMR_Ll_Pl_4=lm_robust(Pl ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
                       +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
                       , cluster=Ec, data=de, se_type="stata")#regression
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LR_Ll_Pl_4=lm(Pl ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
               +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
               , data=de, se_type="stata")#regression
```

```
## Error in model.frame.default(formula = Pl ~ Ll:time2 + Ll:time3 + Ll:time4 + : 'data' must be a data.frame, environment, or list
```

``` r
#table (hypothesis testing):
LMR_Ll_Pl_4$r.squared
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_4' not found
```

``` r
LMR_Ll_Pl_4$nobs
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_4' not found
```

``` r
c(LMR_Ll_Pl_4$coefficients["Ll:time2"],LMR_Ll_Pl_4$std.error["Ll:time2"],LMR_Ll_Pl_4$p.value["Ll:time2"])#t2-t1=Ll:time2
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_4' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_4,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_4' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_4' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_4' not found
```

``` r
ZtestfunLl(LMR_Ll_Pl_4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Ll_Pl_4' not found
```

``` r
#plots:
# tikz(paste0("plot_Pl_Ll_4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Party Likability on Leader Likability") +xlab("Year") +ylab("estimated coefficient") + 
        coord_cartesian(ylim=c(0.66,0.84)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.84-0.66)+0.66))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_4,4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_4,4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_4,4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_4,4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_4,4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Ll_Pl_4,4,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##Table I4##
##table full results:
stargazer(LR_Ll_Pl_m4,LR_Ll_Pl_m2,LR_Ll_Pl_0,LR_Ll_Pl_2,LR_Ll_Pl_4,
          se = list(LMR_Ll_Pl_m4$std.error,LMR_Ll_Pl_m2$std.error,LMR_Ll_Pl_0$std.error,LMR_Ll_Pl_2$std.error,LMR_Ll_Pl_4$std.error))
```

```
## Error in eval(expr, envir, enclos): object 'LR_Ll_Pl_m4' not found
```

``` r
##Pi ON Pl:----
#confidence interval functions:
CI.Pl_Pl10fun=function(CLC,t0,pe){
  CI.Pl=matrix(NA,nrow=59,ncol=4)
  for (t in 1:59) {
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.Pl[t,1]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6#fitted values
    CI.Pl[t,2]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]+2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6"]+
      2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]+2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]+
      2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]+
      2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]#Variance
    CI.Pl[t,3]=CI.Pl[t,1]-qnorm(0.975)*sqrt(CI.Pl[t,2])#95% CI lower
    CI.Pl[t,4]=CI.Pl[t,1]+qnorm(0.975)*sqrt(CI.Pl[t,2])#95% CI upper
  }
  CI.Pl=as.data.frame(CI.Pl)
  CI.Pl$t=c(1961:2019)
  if (pe==1) {CI.Pl=CI.Pl[1:(10+t0),]}
  if (pe==2) {CI.Pl=CI.Pl[(11+t0):(20+t0),]}
  if (pe==3) {CI.Pl=CI.Pl[(21+t0):(30+t0),]}
  if (pe==4) {CI.Pl=CI.Pl[(31+t0):(40+t0),]}
  if (pe==5) {CI.Pl=CI.Pl[(41+t0):(50+t0),]}
  if (pe==6) {CI.Pl=CI.Pl[(51+t0):59,]}
  CI.Pl
}

#Z-test functions:
ZtestfunPl=function(CLC,per1,per2){
  m=CLC$coefficients[paste0("Pl:time",per2)]-CLC$coefficients[paste0("Pl:time",per1)]#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]-
    vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}

#time variables:
t0=0#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
LMR_Pi_Pl_0=lm_robust(Pi ~ Pl:time2+Pl:time3+Pl:time4+Pl:time5+Pl:time6 +I(Ec)
                      +Pl_AUS+Pl_AUT+Pl_CAN+Pl_DEU+Pl_DNK+Pl_ESP+Pl_FIN+Pl_GBR+Pl_GRC+Pl_IRL+Pl_ISL+Pl_ISR+Pl_ITA+Pl_NLD+Pl_NOR+Pl_NZL+Pl_PRT+Pl_SWE-1
                      , cluster=Ec, data=de, se_type="stata")#regression
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LR_Pi_Pl_0=lm(Pi ~ Pl:time2+Pl:time3+Pl:time4+Pl:time5+Pl:time6 +I(Ec)
                      +Pl_AUS+Pl_AUT+Pl_CAN+Pl_DEU+Pl_DNK+Pl_ESP+Pl_FIN+Pl_GBR+Pl_GRC+Pl_IRL+Pl_ISL+Pl_ISR+Pl_ITA+Pl_NLD+Pl_NOR+Pl_NZL+Pl_PRT+Pl_SWE-1
                      , data=de, se_type="stata")#regression
```

```
## Error in model.frame.default(formula = Pi ~ Pl:time2 + Pl:time3 + Pl:time4 + : 'data' must be a data.frame, environment, or list
```

``` r
##Table 1## Party Identification on Party Likability
#table (hypothesis testing):
LMR_Pi_Pl_0$r.squared
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_0' not found
```

``` r
LMR_Pi_Pl_0$nobs
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_0' not found
```

``` r
c(LMR_Pi_Pl_0$coefficients["Pl:time2"],LMR_Pi_Pl_0$std.error["Pl:time2"],LMR_Pi_Pl_0$p.value["Pl:time2"])#t2-t1=Pl:time2
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_0' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_0,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_0' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_0' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_0' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_0' not found
```

``` r
#plots:
# tikz(paste0("plot_Pi_Pl_0.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Party Identif. on Party Likability") +xlab("Year") +ylab("estimated coefficient") + 
        coord_cartesian(ylim=c(0.03,0.07)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.07-0.03)+0.03))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyPi) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_0,0,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_0,0,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_0,0,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_0,0,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_0,0,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_0,0,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyPi' not found
```

``` r
# dev.off()


##Table D2##
##starting value for thresholds -4
#time variables:
t0=-4#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
LMR_Pi_Pl_m4=lm_robust(Pi ~ Pl:time2+Pl:time3+Pl:time4+Pl:time5+Pl:time6 +I(Ec)
                      +Pl_AUS+Pl_AUT+Pl_CAN+Pl_DEU+Pl_DNK+Pl_ESP+Pl_FIN+Pl_GBR+Pl_GRC+Pl_IRL+Pl_ISL+Pl_ISR+Pl_ITA+Pl_NLD+Pl_NOR+Pl_NZL+Pl_PRT+Pl_SWE-1
                      , cluster=Ec, data=de, se_type="stata")#regression
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LR_Pi_Pl_m4=lm(Pi ~ Pl:time2+Pl:time3+Pl:time4+Pl:time5+Pl:time6 +I(Ec)
              +Pl_AUS+Pl_AUT+Pl_CAN+Pl_DEU+Pl_DNK+Pl_ESP+Pl_FIN+Pl_GBR+Pl_GRC+Pl_IRL+Pl_ISL+Pl_ISR+Pl_ITA+Pl_NLD+Pl_NOR+Pl_NZL+Pl_PRT+Pl_SWE-1
              , data=de, se_type="stata")#regression
```

```
## Error in model.frame.default(formula = Pi ~ Pl:time2 + Pl:time3 + Pl:time4 + : 'data' must be a data.frame, environment, or list
```

``` r
#table (hypothesis testing):
LMR_Pi_Pl_m4$r.squared
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_m4' not found
```

``` r
LMR_Pi_Pl_m4$nobs
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_m4' not found
```

``` r
c(LMR_Pi_Pl_m4$coefficients["Pl:time2"],LMR_Pi_Pl_m4$std.error["Pl:time2"],LMR_Pi_Pl_m4$p.value["Pl:time2"])#t2-t1=Pl:time2
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_m4' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_m4,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_m4' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_m4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_m4' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_m4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_m4' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_m4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_m4' not found
```

``` r
#plots:
# tikz(paste0("plot_Pi_Pl_m4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Party Identif. on Party Likability") +xlab("Year") +ylab("estimated coefficient") + 
        coord_cartesian(ylim=c(0.03,0.07)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.07-0.03)+0.03))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyPi) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_m4,-4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_m4,-4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_m4,-4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_m4,-4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_m4,-4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_m4,-4,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyPi' not found
```

``` r
# dev.off()


##starting value for thresholds -2
#time variables:
t0=-2#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
LMR_Pi_Pl_m2=lm_robust(Pi ~ Pl:time2+Pl:time3+Pl:time4+Pl:time5+Pl:time6 +I(Ec)
                       +Pl_AUS+Pl_AUT+Pl_CAN+Pl_DEU+Pl_DNK+Pl_ESP+Pl_FIN+Pl_GBR+Pl_GRC+Pl_IRL+Pl_ISL+Pl_ISR+Pl_ITA+Pl_NLD+Pl_NOR+Pl_NZL+Pl_PRT+Pl_SWE-1
                       , cluster=Ec, data=de, se_type="stata")#regression
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LR_Pi_Pl_m2=lm(Pi ~ Pl:time2+Pl:time3+Pl:time4+Pl:time5+Pl:time6 +I(Ec)
               +Pl_AUS+Pl_AUT+Pl_CAN+Pl_DEU+Pl_DNK+Pl_ESP+Pl_FIN+Pl_GBR+Pl_GRC+Pl_IRL+Pl_ISL+Pl_ISR+Pl_ITA+Pl_NLD+Pl_NOR+Pl_NZL+Pl_PRT+Pl_SWE-1
               , data=de, se_type="stata")#regression
```

```
## Error in model.frame.default(formula = Pi ~ Pl:time2 + Pl:time3 + Pl:time4 + : 'data' must be a data.frame, environment, or list
```

``` r
#table (hypothesis testing):
LMR_Pi_Pl_m2$r.squared
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_m2' not found
```

``` r
LMR_Pi_Pl_m2$nobs
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_m2' not found
```

``` r
c(LMR_Pi_Pl_m2$coefficients["Pl:time2"],LMR_Pi_Pl_m2$std.error["Pl:time2"],LMR_Pi_Pl_m2$p.value["Pl:time2"])#t2-t1=Pl:time2
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_m2' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_m2,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_m2' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_m2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_m2' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_m2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_m2' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_m2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_m2' not found
```

``` r
#plots:
# tikz(paste0("plot_Pi_Pl_m2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Party Identif. on Party Likability") +xlab("Year") +ylab("estimated coefficient") + 
        coord_cartesian(ylim=c(0.03,0.07)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.07-0.03)+0.03))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyPi) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_m2,-2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_m2,-2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_m2,-2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_m2,-2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_m2,-2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_m2,-2,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyPi' not found
```

``` r
# dev.off()


##starting value for thresholds 2
#time variables:
t0=2#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
LMR_Pi_Pl_2=lm_robust(Pi ~ Pl:time2+Pl:time3+Pl:time4+Pl:time5+Pl:time6 +I(Ec)
                       +Pl_AUS+Pl_AUT+Pl_CAN+Pl_DEU+Pl_DNK+Pl_ESP+Pl_FIN+Pl_GBR+Pl_GRC+Pl_IRL+Pl_ISL+Pl_ISR+Pl_ITA+Pl_NLD+Pl_NOR+Pl_NZL+Pl_PRT+Pl_SWE-1
                       , cluster=Ec, data=de, se_type="stata")#regression
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LR_Pi_Pl_2=lm(Pi ~ Pl:time2+Pl:time3+Pl:time4+Pl:time5+Pl:time6 +I(Ec)
               +Pl_AUS+Pl_AUT+Pl_CAN+Pl_DEU+Pl_DNK+Pl_ESP+Pl_FIN+Pl_GBR+Pl_GRC+Pl_IRL+Pl_ISL+Pl_ISR+Pl_ITA+Pl_NLD+Pl_NOR+Pl_NZL+Pl_PRT+Pl_SWE-1
               , data=de, se_type="stata")#regression
```

```
## Error in model.frame.default(formula = Pi ~ Pl:time2 + Pl:time3 + Pl:time4 + : 'data' must be a data.frame, environment, or list
```

``` r
#table (hypothesis testing):
LMR_Pi_Pl_2$r.squared
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_2' not found
```

``` r
LMR_Pi_Pl_2$nobs
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_2' not found
```

``` r
c(LMR_Pi_Pl_2$coefficients["Pl:time2"],LMR_Pi_Pl_2$std.error["Pl:time2"],LMR_Pi_Pl_2$p.value["Pl:time2"])#t2-t1=Pl:time2
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_2' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_2,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_2' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_2' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_2' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_2' not found
```

``` r
#plots:
# tikz(paste0("plot_Pi_Pl_2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Party Identif. on Party Likability") +xlab("Year") +ylab("estimated coefficient") + 
        coord_cartesian(ylim=c(0.03,0.07)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.07-0.03)+0.03))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyPi) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_2,2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_2,2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_2,2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_2,2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_2,2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_2,2,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyPi' not found
```

``` r
# dev.off()


##starting value for thresholds -4
#time variables:
t0=4#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
LMR_Pi_Pl_4=lm_robust(Pi ~ Pl:time2+Pl:time3+Pl:time4+Pl:time5+Pl:time6 +I(Ec)
                       +Pl_AUS+Pl_AUT+Pl_CAN+Pl_DEU+Pl_DNK+Pl_ESP+Pl_FIN+Pl_GBR+Pl_GRC+Pl_IRL+Pl_ISL+Pl_ISR+Pl_ITA+Pl_NLD+Pl_NOR+Pl_NZL+Pl_PRT+Pl_SWE-1
                       , cluster=Ec, data=de, se_type="stata")#regression
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LR_Pi_Pl_4=lm(Pi ~ Pl:time2+Pl:time3+Pl:time4+Pl:time5+Pl:time6 +I(Ec)
               +Pl_AUS+Pl_AUT+Pl_CAN+Pl_DEU+Pl_DNK+Pl_ESP+Pl_FIN+Pl_GBR+Pl_GRC+Pl_IRL+Pl_ISL+Pl_ISR+Pl_ITA+Pl_NLD+Pl_NOR+Pl_NZL+Pl_PRT+Pl_SWE-1
               , data=de, se_type="stata")#regression
```

```
## Error in model.frame.default(formula = Pi ~ Pl:time2 + Pl:time3 + Pl:time4 + : 'data' must be a data.frame, environment, or list
```

``` r
#table (hypothesis testing):
LMR_Pi_Pl_4$r.squared
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_4' not found
```

``` r
LMR_Pi_Pl_4$nobs
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_4' not found
```

``` r
c(LMR_Pi_Pl_4$coefficients["Pl:time2"],LMR_Pi_Pl_4$std.error["Pl:time2"],LMR_Pi_Pl_4$p.value["Pl:time2"])#t2-t1=Pl:time2
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_4' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_4,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_4' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_4' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_4' not found
```

``` r
ZtestfunPl(LMR_Pi_Pl_4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Pl_4' not found
```

``` r
#plots:
# tikz(paste0("plot_Pi_Pl_4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Party Identif. on Party Likability") +xlab("Year") +ylab("estimated coefficient") + 
        coord_cartesian(ylim=c(0.03,0.07)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.07-0.03)+0.03))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyPi) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_4,4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_4,4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_4,4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_4,4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_4,4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pl_Pl10fun(LMR_Pi_Pl_4,4,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyPi' not found
```

``` r
# dev.off()


##Table I4##
##table full results:
stargazer(LR_Pi_Pl_m4,LR_Pi_Pl_m2,LR_Pi_Pl_0,LR_Pi_Pl_2,LR_Pi_Pl_4,
          se = list(LMR_Pi_Pl_m4$std.error,LMR_Pi_Pl_m2$std.error,LMR_Pi_Pl_0$std.error,LMR_Pi_Pl_2$std.error,LMR_Pi_Pl_4$std.error))
```

```
## Error in eval(expr, envir, enclos): object 'LR_Pi_Pl_m4' not found
```

``` r
##Pi ON Ll AND TABLE RESULTS:----

#confidence interval functions:
CI.Ll_Pl10fun=function(CLC,t0,pe){
  CI.Ll=matrix(NA,nrow=59,ncol=4)
  for (t in 1:59) {
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.Ll[t,1]=CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6#fitted values
    CI.Ll[t,2]=1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]+
      2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]+
      2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]+
      2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]+
      2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]+
      2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]#Variance
    CI.Ll[t,3]=CI.Ll[t,1]-qnorm(0.975)*sqrt(CI.Ll[t,2])#95% CI lower
    CI.Ll[t,4]=CI.Ll[t,1]+qnorm(0.975)*sqrt(CI.Ll[t,2])#95% CI upper
  }
  CI.Ll=as.data.frame(CI.Ll)
  CI.Ll$t=c(1961:2019)
  if (pe==1) {CI.Ll=CI.Ll[1:(10+t0),]}
  if (pe==2) {CI.Ll=CI.Ll[(11+t0):(20+t0),]}
  if (pe==3) {CI.Ll=CI.Ll[(21+t0):(30+t0),]}
  if (pe==4) {CI.Ll=CI.Ll[(31+t0):(40+t0),]}
  if (pe==5) {CI.Ll=CI.Ll[(41+t0):(50+t0),]}
  if (pe==6) {CI.Ll=CI.Ll[(51+t0):59,]}
  CI.Ll
}

#Z-test functions:
ZtestfunLl=function(CLC,per1,per2){
  m=CLC$coefficients[paste0("Ll:time",per2)]-CLC$coefficients[paste0("Ll:time",per1)]#mean
  v=vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]-
    vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}

#time variables:
t0=0#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
LMR_Pi_Ll_0=lm_robust(Pi ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
                      +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
                      , cluster=Ec, data=de, se_type="stata")#regression
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LR_Pi_Ll_0=lm(Pi ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
                      +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
                      , data=de, se_type="stata")#regression
```

```
## Error in model.frame.default(formula = Pi ~ Ll:time2 + Ll:time3 + Ll:time4 + : 'data' must be a data.frame, environment, or list
```

``` r
##Table 1## Party Identification on Leader Likability
#table (hypothesis testing):
LMR_Pi_Ll_0$r.squared
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_0' not found
```

``` r
LMR_Pi_Ll_0$nobs
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_0' not found
```

``` r
c(LMR_Pi_Ll_0$coefficients["Ll:time2"],LMR_Pi_Ll_0$std.error["Ll:time2"],LMR_Pi_Ll_0$p.value["Ll:time2"])#t2-t1=Ll:time2
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_0' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_0,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_0' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_0' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_0' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_0' not found
```

``` r
#plots:
# tikz(paste0("plot_Pi_Ll_0.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Party Identif. on Leader Likability") +xlab("Year") +ylab("estimated coefficient") + 
        coord_cartesian(ylim=c(0.03,0.07)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.07-0.03)+0.03))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyPi) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_0,0,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_0,0,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_0,0,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_0,0,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_0,0,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_0,0,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyPi' not found
```

``` r
# dev.off()


##Table D3##
##table full results:
stargazer(LR_Ll_Pl_0,LR_Pi_Pl_0,LR_Pi_Ll_0,
          se = list(LMR_Ll_Pl_0$std.error,LMR_Pi_Pl_0$std.error,LMR_Pi_Ll_0$std.error))
```

```
## Error in eval(expr, envir, enclos): object 'LR_Ll_Pl_0' not found
```

``` r
##starting value for thresholds -4
#time variables:
t0=-4#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
LMR_Pi_Ll_m4=lm_robust(Pi ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
                      +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
                      , cluster=Ec, data=de, se_type="stata")#regression
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LR_Pi_Ll_m4=lm(Pi ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
              +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
              , data=de, se_type="stata")#regression
```

```
## Error in model.frame.default(formula = Pi ~ Ll:time2 + Ll:time3 + Ll:time4 + : 'data' must be a data.frame, environment, or list
```

``` r
#table (hypothesis testing):
LMR_Pi_Ll_m4$r.squared
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_m4' not found
```

``` r
LMR_Pi_Ll_m4$nobs
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_m4' not found
```

``` r
c(LMR_Pi_Ll_m4$coefficients["Ll:time2"],LMR_Pi_Ll_m4$std.error["Ll:time2"],LMR_Pi_Ll_m4$p.value["Ll:time2"])#t2-t1=Ll:time2
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_m4' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_m4,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_m4' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_m4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_m4' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_m4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_m4' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_m4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_m4' not found
```

``` r
#plots:
# tikz(paste0("plot_Pi_Ll_m4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Party Identif. on Leader Likability") +xlab("Year") +ylab("estimated coefficient") + 
        coord_cartesian(ylim=c(0.03,0.07)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.07-0.03)+0.03))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyPi) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_m4,-4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_m4,-4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_m4,-4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_m4,-4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_m4,-4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_m4,-4,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyPi' not found
```

``` r
# dev.off()


##starting value for thresholds -2
#time variables:
t0=-2#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
LMR_Pi_Ll_m2=lm_robust(Pi ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
                       +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
                       , cluster=Ec, data=de, se_type="stata")#regression
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LR_Pi_Ll_m2=lm(Pi ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
               +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
               , data=de, se_type="stata")#regression
```

```
## Error in model.frame.default(formula = Pi ~ Ll:time2 + Ll:time3 + Ll:time4 + : 'data' must be a data.frame, environment, or list
```

``` r
#table (hypothesis testing):
LMR_Pi_Ll_m2$r.squared
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_m2' not found
```

``` r
LMR_Pi_Ll_m2$nobs
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_m2' not found
```

``` r
c(LMR_Pi_Ll_m2$coefficients["Ll:time2"],LMR_Pi_Ll_m2$std.error["Ll:time2"],LMR_Pi_Ll_m2$p.value["Ll:time2"])#t2-t1=Ll:time2
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_m2' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_m2,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_m2' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_m2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_m2' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_m2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_m2' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_m2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_m2' not found
```

``` r
#plots:
# tikz(paste0("plot_Pi_Ll_m2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Party Identif. on Leader Likability") +xlab("Year") +ylab("estimated coefficient") + 
        coord_cartesian(ylim=c(0.03,0.07)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.07-0.03)+0.03))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyPi) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_m2,-2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_m2,-2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_m2,-2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_m2,-2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_m2,-2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_m2,-2,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyPi' not found
```

``` r
# dev.off()


##starting value for thresholds 2
#time variables:
t0=2#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
LMR_Pi_Ll_2=lm_robust(Pi ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
                       +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
                       , cluster=Ec, data=de, se_type="stata")#regression
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LR_Pi_Ll_2=lm(Pi ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
               +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
               , data=de, se_type="stata")#regression
```

```
## Error in model.frame.default(formula = Pi ~ Ll:time2 + Ll:time3 + Ll:time4 + : 'data' must be a data.frame, environment, or list
```

``` r
#table (hypothesis testing):
LMR_Pi_Ll_2$r.squared
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_2' not found
```

``` r
LMR_Pi_Ll_2$nobs
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_2' not found
```

``` r
c(LMR_Pi_Ll_2$coefficients["Ll:time2"],LMR_Pi_Ll_2$std.error["Ll:time2"],LMR_Pi_Ll_2$p.value["Ll:time2"])#t2-t1=Ll:time2
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_2' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_2,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_2' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_2' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_2' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_2' not found
```

``` r
#plots:
# tikz(paste0("plot_Pi_Ll_2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Party Identif. on Leader Likability") +xlab("Year") +ylab("estimated coefficient") + 
        coord_cartesian(ylim=c(0.03,0.07)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.07-0.03)+0.03))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyPi) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_2,2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_2,2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_2,2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_2,2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_2,2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_2,2,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyPi' not found
```

``` r
# dev.off()


##starting value for thresholds 4
#time variables:
t0=4#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
LMR_Pi_Ll_4=lm_robust(Pi ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
                       +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
                       , cluster=Ec, data=de, se_type="stata")#regression
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LR_Pi_Ll_4=lm(Pi ~ Ll:time2+Ll:time3+Ll:time4+Ll:time5+Ll:time6 +I(Ec)
               +Ll_AUS+Ll_AUT+Ll_CAN+Ll_DEU+Ll_DNK+Ll_ESP+Ll_FIN+Ll_GBR+Ll_GRC+Ll_IRL+Ll_ISL+Ll_ISR+Ll_ITA+Ll_NLD+Ll_NOR+Ll_NZL+Ll_PRT+Ll_SWE-1
               , data=de, se_type="stata")#regression
```

```
## Error in model.frame.default(formula = Pi ~ Ll:time2 + Ll:time3 + Ll:time4 + : 'data' must be a data.frame, environment, or list
```

``` r
#table (hypothesis testing):
LMR_Pi_Ll_4$r.squared
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_4' not found
```

``` r
LMR_Pi_Ll_4$nobs
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_4' not found
```

``` r
c(LMR_Pi_Ll_4$coefficients["Ll:time2"],LMR_Pi_Ll_4$std.error["Ll:time2"],LMR_Pi_Ll_4$p.value["Ll:time2"])#t2-t1=Ll:time2
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_4' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_4,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_4' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_4' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_4' not found
```

``` r
ZtestfunLl(LMR_Pi_Ll_4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'LMR_Pi_Ll_4' not found
```

``` r
#plots:
# tikz(paste0("plot_Pi_Ll_4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Party Identif. on Leader Likability") +xlab("Year") +ylab("estimated coefficient") + 
        coord_cartesian(ylim=c(0.03,0.07)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.07-0.03)+0.03))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyPi) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_4,4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_4,4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_4,4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_4,4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_4,4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Ll_Pl10fun(LMR_Pi_Ll_4,4,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyPi' not found
```

``` r
# dev.off()


##Table I5##
##table full results:
stargazer(LR_Pi_Ll_m4,LR_Pi_Ll_m2,LR_Pi_Ll_0,LR_Pi_Ll_2,LR_Pi_Ll_4,
          se = list(LMR_Pi_Ll_m4$std.error,LMR_Pi_Ll_m2$std.error,LMR_Pi_Ll_0$std.error,LMR_Pi_Ll_2$std.error,LMR_Pi_Ll_4$std.error))
```

```
## Error in eval(expr, envir, enclos): object 'LR_Pi_Ll_m4' not found
```

``` r
#ANALYSIS 10Y SEGMENTS:----

#confidence interval functions:
CI.PlLllses10funCTY=function(CLC,t0,pe,cty){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=4)#Pl:
  for (t in 1:59) {
    # t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.PlLl[t,1]=CLC$coefficients[paste0("Pl_",cty)]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6-
      (CLC$coefficients[paste0("Ll_",cty)]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)[paste0("Pl_",cty),paste0("Pl_",cty)]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      1*vcov(CLC)[paste0("Ll_",cty),paste0("Ll_",cty)]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]-
      2*1*1*vcov(CLC)[paste0("Pl_",cty),paste0("Ll_",cty)]+2*1*t2*vcov(CLC)[paste0("Pl_",cty),"Pl:time2"]-2*1*t2*vcov(CLC)[paste0("Pl_",cty),"Ll:time2"]+2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Pl:time3"]-2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Ll:time3"]+
      2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Pl:time4"]-2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Ll:time4"]+2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Pl:time5"]-2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Ll:time5"]+2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Pl:time6"]-2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Ll:time6"]-
      2*1*t2*vcov(CLC)[paste0("Ll_",cty),"Pl:time2"]+2*1*t2*vcov(CLC)[paste0("Ll_",cty),"Ll:time2"]-2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Pl:time3"]+2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Ll:time3"]-
      2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Pl:time4"]+2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Ll:time4"]-2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Pl:time5"]+2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Ll:time5"]-2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Pl:time6"]+2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Ll:time6"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  if (pe==1) {CI.PlLl=CI.PlLl[1:(10+t0),]}
  if (pe==2) {CI.PlLl=CI.PlLl[(11+t0):(20+t0),]}
  if (pe==3) {CI.PlLl=CI.PlLl[(21+t0):(30+t0),]}
  if (pe==4) {CI.PlLl=CI.PlLl[(31+t0):(40+t0),]}
  if (pe==5) {CI.PlLl=CI.PlLl[(41+t0):(50+t0),]}
  if (pe==6) {CI.PlLl=CI.PlLl[(51+t0):59,]}
  CI.PlLl
}
CI.Pllses10fun=function(CLC,t0,pe){ #function creating Confidence Interval for Pl
  CI.Pl=matrix(NA,nrow=59,ncol=4)#Pl:
  for (t in 1:59) {
    # t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.Pl[t,1]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6#fitted values
    CI.Pl[t,2]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]+2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6"]+
      2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]+2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]+
      2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]+
      2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]#Variance
    CI.Pl[t,3]=CI.Pl[t,1]-qnorm(0.975)*sqrt(CI.Pl[t,2])#95% CI lower
    CI.Pl[t,4]=CI.Pl[t,1]+qnorm(0.975)*sqrt(CI.Pl[t,2])#95% CI upper
  }
  CI.Pl=as.data.frame(CI.Pl)
  CI.Pl$t=c(1961:2019)
  if (pe==1) {CI.Pl=CI.Pl[1:(10+t0),]}
  if (pe==2) {CI.Pl=CI.Pl[(11+t0):(20+t0),]}
  if (pe==3) {CI.Pl=CI.Pl[(21+t0):(30+t0),]}
  if (pe==4) {CI.Pl=CI.Pl[(31+t0):(40+t0),]}
  if (pe==5) {CI.Pl=CI.Pl[(41+t0):(50+t0),]}
  if (pe==6) {CI.Pl=CI.Pl[(51+t0):59,]}
  CI.Pl
}
CI.Lllses10fun=function(CLC,t0,pe){ #function creating Confidence Interval for Ll
  CI.Ll=matrix(NA,nrow=59,ncol=4)#Ll:
  for (t in 1:59) {
    # t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.Ll[t,1]=CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6#fitted values
    CI.Ll[t,2]=1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]+
      2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]+
      2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]+
      2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]+
      2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]+
      2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]#Variance
    CI.Ll[t,3]=CI.Ll[t,1]-qnorm(0.975)*sqrt(CI.Ll[t,2])#95% CI lower
    CI.Ll[t,4]=CI.Ll[t,1]+qnorm(0.975)*sqrt(CI.Ll[t,2])#95% CI upper
  }
  CI.Ll=as.data.frame(CI.Ll)
  CI.Ll$t=c(1961:2019)
  if (pe==1) {CI.Ll=CI.Ll[1:(10+t0),]}
  if (pe==2) {CI.Ll=CI.Ll[(11+t0):(20+t0),]}
  if (pe==3) {CI.Ll=CI.Ll[(21+t0):(30+t0),]}
  if (pe==4) {CI.Ll=CI.Ll[(31+t0):(40+t0),]}
  if (pe==5) {CI.Ll=CI.Ll[(41+t0):(50+t0),]}
  if (pe==6) {CI.Ll=CI.Ll[(51+t0):59,]}
  CI.Ll
}

#Z-test functions:
ZtestfunT12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2)]-CLC$coefficients[paste0("Ll:time",2)]#mean
  v=vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2)]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunT16=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",6)]-CLC$coefficients[paste0("Ll:time",6)]#mean
  v=vcov(CLC)[paste0("Pl:time",6),paste0("Pl:time",6)]+vcov(CLC)[paste0("Ll:time",6),paste0("Ll:time",6)]-
    6*vcov(CLC)[paste0("Pl:time",6),paste0("Ll:time",6)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunT=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}

#time variables:
t0=0#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
CLC_lses10_0=clogit(Va ~ Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                      +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                    +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time2 + Ll:time2 + Pl:time3 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_lses10_0$coefficients)[names(CLC_lses10_0$coefficients)=="time2:Ll"]="Ll:time2"
```

```
## Error: object 'CLC_lses10_0' not found
```

``` r
##Table 2##
#table (hypothesis testing):
stargazer(CLC_lses10_0,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_0' not found
```

``` r
ZtestfunT12(CLC_lses10_0)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_0' not found
```

``` r
ZtestfunT(CLC_lses10_0,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_0' not found
```

``` r
ZtestfunT(CLC_lses10_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_0' not found
```

``` r
ZtestfunT(CLC_lses10_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_0' not found
```

``` r
ZtestfunT(CLC_lses10_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_0' not found
```

``` r
#difference between 60s and 2010s:
ZtestfunT16(CLC_lses10_0)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_0' not found
```

``` r
#difference between 80s and 2010s:
ZtestfunT(CLC_lses10_0,3,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_0' not found
```

``` r
#list and test countries by average variance:
vaCLC_lses10_0=matrix(NA,nrow=length(sort(unique(de$Ec))),ncol=2)#average variance by country over time
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
for(i in 1:length(sort(unique(de$Ec)))) {#get average variance over time
  vaCLC_lses10_0[i,1]=paste0(sort(unique(de$Ec))[i])
  vaCLC_lses10_0[i,2]=mean(CI.PlLllses10funCTY(CLC_lses10_0,0,4,sort(unique(de$Ec))[i])[,2],na.rm=T)
}
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
vaCLC_lses10_0=as.data.frame(vaCLC_lses10_0)
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_lses10_0' not found
```

``` r
vaCLC_lses10_0=vaCLC_lses10_0[order(vaCLC_lses10_0$V2),]
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_lses10_0' not found
```

``` r
vaCLC_lses10_0[9,1]#country with median variance (the same considering each period)
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_lses10_0' not found
```

``` r
vaCLC_lses10_0[,1]#list of countries by variance (small to high)#virtually the same than two periods
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_lses10_0' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses10_0","_PlLl.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_0,0,1,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_0,0,2,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_0,0,3,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_0,0,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_0,0,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_0,0,6,sort(unique(de$Ec))[11])) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##Figure 3##
##plots only Pl,Ll:
# tikz(paste0("plot_","CLC_lses10","_Pl_0.tex"),width=4, height=3)#plot Pl:
plot( ggplot()
      +ggtitle("")
      +xlab("Year") +ylab("Party Effect") + coord_cartesian(ylim=c(0.5001,0.7)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.7-0.5001)+0.5001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_0,0,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_0,0,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_0,0,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_0,0,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_0,0,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_0,0,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","CLC_lses10","_Ll_0.tex"),width=4, height=3)#plot Ll:
plot( ggplot()
      +ggtitle("")
      +xlab("Year") +ylab("Leader Effect") + coord_cartesian(ylim=c(0.0001,0.2)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.2-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_0,0,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_0,0,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_0,0,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_0,0,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_0,0,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_0,0,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##ANALYSIS 10Y SEGMENTS - ALTERNATIVE THRESHOLDS AND FULL REUSLTS TABLE:----

#confidence interval functions:
CI.PlLllses10funCTY=function(CLC,t0,pe,cty){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=4)#Pl:
  for (t in 1:59) {
    # t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.PlLl[t,1]=CLC$coefficients[paste0("Pl_",cty)]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6-
      (CLC$coefficients[paste0("Ll_",cty)]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)[paste0("Pl_",cty),paste0("Pl_",cty)]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      1*vcov(CLC)[paste0("Ll_",cty),paste0("Ll_",cty)]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]-
      2*1*1*vcov(CLC)[paste0("Pl_",cty),paste0("Ll_",cty)]+2*1*t2*vcov(CLC)[paste0("Pl_",cty),"Pl:time2"]-2*1*t2*vcov(CLC)[paste0("Pl_",cty),"Ll:time2"]+2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Pl:time3"]-2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Ll:time3"]+
      2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Pl:time4"]-2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Ll:time4"]+2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Pl:time5"]-2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Ll:time5"]+2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Pl:time6"]-2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Ll:time6"]-
      2*1*t2*vcov(CLC)[paste0("Ll_",cty),"Pl:time2"]+2*1*t2*vcov(CLC)[paste0("Ll_",cty),"Ll:time2"]-2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Pl:time3"]+2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Ll:time3"]-
      2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Pl:time4"]+2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Ll:time4"]-2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Pl:time5"]+2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Ll:time5"]-2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Pl:time6"]+2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Ll:time6"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  if (pe==1) {CI.PlLl=CI.PlLl[1:(10+t0),]}
  if (pe==2) {CI.PlLl=CI.PlLl[(11+t0):(20+t0),]}
  if (pe==3) {CI.PlLl=CI.PlLl[(21+t0):(30+t0),]}
  if (pe==4) {CI.PlLl=CI.PlLl[(31+t0):(40+t0),]}
  if (pe==5) {CI.PlLl=CI.PlLl[(41+t0):(50+t0),]}
  if (pe==6) {CI.PlLl=CI.PlLl[(51+t0):59,]}
  CI.PlLl
}
CI.Pllses10fun=function(CLC,t0,pe){ #function creating Confidence Interval for Pl
  CI.Pl=matrix(NA,nrow=59,ncol=4)#Pl:
  for (t in 1:59) {
    # t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.Pl[t,1]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6#fitted values
    CI.Pl[t,2]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]+2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6"]+
      2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]+2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]+
      2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]+
      2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]#Variance
    CI.Pl[t,3]=CI.Pl[t,1]-qnorm(0.975)*sqrt(CI.Pl[t,2])#95% CI lower
    CI.Pl[t,4]=CI.Pl[t,1]+qnorm(0.975)*sqrt(CI.Pl[t,2])#95% CI upper
  }
  CI.Pl=as.data.frame(CI.Pl)
  CI.Pl$t=c(1961:2019)
  if (pe==1) {CI.Pl=CI.Pl[1:(10+t0),]}
  if (pe==2) {CI.Pl=CI.Pl[(11+t0):(20+t0),]}
  if (pe==3) {CI.Pl=CI.Pl[(21+t0):(30+t0),]}
  if (pe==4) {CI.Pl=CI.Pl[(31+t0):(40+t0),]}
  if (pe==5) {CI.Pl=CI.Pl[(41+t0):(50+t0),]}
  if (pe==6) {CI.Pl=CI.Pl[(51+t0):59,]}
  CI.Pl
}
CI.Lllses10fun=function(CLC,t0,pe){ #function creating Confidence Interval for Ll
  CI.Ll=matrix(NA,nrow=59,ncol=4)#Ll:
  for (t in 1:59) {
    # t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.Ll[t,1]=CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6#fitted values
    CI.Ll[t,2]=1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]+
      2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]+
      2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]+
      2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]+
      2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]+
      2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]#Variance
    CI.Ll[t,3]=CI.Ll[t,1]-qnorm(0.975)*sqrt(CI.Ll[t,2])#95% CI lower
    CI.Ll[t,4]=CI.Ll[t,1]+qnorm(0.975)*sqrt(CI.Ll[t,2])#95% CI upper
  }
  CI.Ll=as.data.frame(CI.Ll)
  CI.Ll$t=c(1961:2019)
  if (pe==1) {CI.Ll=CI.Ll[1:(10+t0),]}
  if (pe==2) {CI.Ll=CI.Ll[(11+t0):(20+t0),]}
  if (pe==3) {CI.Ll=CI.Ll[(21+t0):(30+t0),]}
  if (pe==4) {CI.Ll=CI.Ll[(31+t0):(40+t0),]}
  if (pe==5) {CI.Ll=CI.Ll[(41+t0):(50+t0),]}
  if (pe==6) {CI.Ll=CI.Ll[(51+t0):59,]}
  CI.Ll
}

#Z-test functions:
ZtestfunT12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2)]-CLC$coefficients[paste0("Ll:time",2)]#mean
  v=vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2)]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunT=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}


##Table D4## and ##Figure D1##
##starting value for thresholds -4
#time variables:
t0=-4#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
CLC_lses10_m4=clogit(Va ~ Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                      +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                    +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time2 + Ll:time2 + Pl:time3 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_lses10_m4$coefficients)[names(CLC_lses10_m4$coefficients)=="time2:Ll"]="Ll:time2"
```

```
## Error: object 'CLC_lses10_m4' not found
```

``` r
#table (hypothesis testing):
stargazer(CLC_lses10_m4,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_m4' not found
```

``` r
ZtestfunT12(CLC_lses10_m4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_m4' not found
```

``` r
ZtestfunT(CLC_lses10_m4,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_m4' not found
```

``` r
ZtestfunT(CLC_lses10_m4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_m4' not found
```

``` r
ZtestfunT(CLC_lses10_m4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_m4' not found
```

``` r
ZtestfunT(CLC_lses10_m4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_m4' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_CLC_lses10_0_PlLl_m4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("thresholds offset -4") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_m4,-4,1,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_m4,-4,2,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_m4,-4,3,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_m4,-4,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_m4,-4,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_m4,-4,6,sort(unique(de$Ec))[11])) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()

##plots only Pl,Ll:
# tikz(paste0("plot_","CLC_lses10","_Pl_m4.tex"),width=4, height=3)#plot Pl:
plot( ggplot()
      +ggtitle("")
      +xlab("Year") +ylab("Party Effect") + coord_cartesian(ylim=c(0.5001,0.7)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.7-0.5001)+0.5001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_m4,-4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_m4,-4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_m4,-4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_m4,-4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_m4,-4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_m4,-4,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","CLC_lses10","_Ll_m4.tex"),width=4, height=3)#plot Ll:
plot( ggplot()
      +ggtitle("")
      +xlab("Year") +ylab("Leader Effect") + coord_cartesian(ylim=c(0.0001,0.2)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.2-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_m4,-4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_m4,-4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_m4,-4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_m4,-4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_m4,-4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_m4,-4,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##starting value for thresholds -2
#time variables:
t0=-2#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
CLC_lses10_m2=clogit(Va ~ Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                       +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                     +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time2 + Ll:time2 + Pl:time3 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_lses10_m2$coefficients)[names(CLC_lses10_m2$coefficients)=="time2:Ll"]="Ll:time2"
```

```
## Error: object 'CLC_lses10_m2' not found
```

``` r
#table (hypothesis testing):
stargazer(CLC_lses10_m2,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_m2' not found
```

``` r
ZtestfunT12(CLC_lses10_m2)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_m2' not found
```

``` r
ZtestfunT(CLC_lses10_m2,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_m2' not found
```

``` r
ZtestfunT(CLC_lses10_m2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_m2' not found
```

``` r
ZtestfunT(CLC_lses10_m2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_m2' not found
```

``` r
ZtestfunT(CLC_lses10_m2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_m2' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_CLC_lses10_0_PlLl_m2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("thresholds offset -2") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_m2,-2,1,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_m2,-2,2,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_m2,-2,3,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_m2,-2,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_m2,-2,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_m2,-2,6,sort(unique(de$Ec))[11])) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()

##plots only Pl,Ll:
# tikz(paste0("plot_","CLC_lses10","_Pl_m2.tex"),width=4, height=3)#plot Pl:
plot( ggplot()
      +ggtitle("")
      +xlab("Year") +ylab("Party Effect") + coord_cartesian(ylim=c(0.5001,0.7)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.7-0.5001)+0.5001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_m2,-2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_m2,-2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_m2,-2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_m2,-2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_m2,-2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_m2,-2,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","CLC_lses10","_Ll_m2.tex"),width=4, height=3)#plot Ll:
plot( ggplot()
      +ggtitle("")
      +xlab("Year") +ylab("Leader Effect") + coord_cartesian(ylim=c(0.0001,0.2)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.2-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_m2,-2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_m2,-2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_m2,-2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_m2,-2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_m2,-2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_m2,-2,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##starting value for thresholds 2
#time variables:
t0=2#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
CLC_lses10_2=clogit(Va ~ Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                       +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                     +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time2 + Ll:time2 + Pl:time3 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_lses10_2$coefficients)[names(CLC_lses10_2$coefficients)=="time2:Ll"]="Ll:time2"
```

```
## Error: object 'CLC_lses10_2' not found
```

``` r
#table (hypothesis testing):
stargazer(CLC_lses10_2,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_2' not found
```

``` r
ZtestfunT12(CLC_lses10_2)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_2' not found
```

``` r
ZtestfunT(CLC_lses10_2,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_2' not found
```

``` r
ZtestfunT(CLC_lses10_2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_2' not found
```

``` r
ZtestfunT(CLC_lses10_2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_2' not found
```

``` r
ZtestfunT(CLC_lses10_2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_2' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_CLC_lses10_0_PlLl_2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("thresholds offset +2") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_2,2,1,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_2,2,2,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_2,2,3,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_2,2,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_2,2,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_2,2,6,sort(unique(de$Ec))[11])) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()

##plots only Pl,Ll:
# tikz(paste0("plot_","CLC_lses10","_Pl_2.tex"),width=4, height=3)#plot Pl:
plot( ggplot()
      +ggtitle("")
      +xlab("Year") +ylab("Party Effect") + coord_cartesian(ylim=c(0.5001,0.7)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.7-0.5001)+0.5001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_2,2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_2,2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_2,2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_2,2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_2,2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_2,2,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","CLC_lses10","_Ll_2.tex"),width=4, height=3)#plot Ll:
plot( ggplot()
      +ggtitle("")
      +xlab("Year") +ylab("Leader Effect") + coord_cartesian(ylim=c(0.0001,0.2)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.2-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_2,2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_2,2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_2,2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_2,2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_2,2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_2,2,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##starting value for thresholds 4
#time variables:
t0=4#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
CLC_lses10_4=clogit(Va ~ Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                       +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                     +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time2 + Ll:time2 + Pl:time3 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_lses10_4$coefficients)[names(CLC_lses10_4$coefficients)=="time2:Ll"]="Ll:time2"
```

```
## Error: object 'CLC_lses10_4' not found
```

``` r
#table (hypothesis testing):
stargazer(CLC_lses10_4,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_4' not found
```

``` r
ZtestfunT12(CLC_lses10_4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_4' not found
```

``` r
ZtestfunT(CLC_lses10_4,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_4' not found
```

``` r
ZtestfunT(CLC_lses10_4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_4' not found
```

``` r
ZtestfunT(CLC_lses10_4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_4' not found
```

``` r
ZtestfunT(CLC_lses10_4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_4' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_CLC_lses10_0_PlLl_4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("thresholds offset +4") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_4,4,1,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_4,4,2,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_4,4,3,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_4,4,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_4,4,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10funCTY(CLC_lses10_4,4,6,sort(unique(de$Ec))[11])) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()

##plots only Pl,Ll:
# tikz(paste0("plot_","CLC_lses10","_Pl_4.tex"),width=4, height=3)#plot Pl:
plot( ggplot()
      +ggtitle("")
      +xlab("Year") +ylab("Party Effect") + coord_cartesian(ylim=c(0.5001,0.7)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.7-0.5001)+0.5001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_4,4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_4,4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_4,4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_4,4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_4,4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses10_4,4,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","CLC_lses10","_Ll_4.tex"),width=4, height=3)#plot Ll:
plot( ggplot()
      +ggtitle("")
      +xlab("Year") +ylab("Leader Effect") + coord_cartesian(ylim=c(0.0001,0.2)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.2-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_4,4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_4,4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_4,4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_4,4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_4,4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses10_4,4,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##Table I6##
##table full results:
cm4=CLC_lses10_m4#shorten name for stargazer:
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_m4' not found
```

``` r
cm2=CLC_lses10_m2
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_m2' not found
```

``` r
c0=CLC_lses10_0
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_0' not found
```

``` r
c2=CLC_lses10_2
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_2' not found
```

``` r
c4=CLC_lses10_4
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_4' not found
```

``` r
stargazer(cm4,cm2,c0,c2,c4)#table
```

```
## Error in eval(expr, envir, enclos): object 'cm4' not found
```

``` r
rm(cm4,cm2,c0,c2,c4)


##ANALYSIS 10Y SEGMENTS EU - NON EU:----

#EU dummy:
de$DL[de$Ec %in% c("AUS","CAN","ISR","NZL")]=1#non EU
```

```
## Error in `*tmp*`$DL: object of type 'closure' is not subsettable
```

``` r
de$DL[!de$Ec %in% c("AUS","CAN","ISR","NZL")]=0#EU
```

```
## Error in `*tmp*`$DL: object of type 'closure' is not subsettable
```

``` r
#confidence interval functions:
CI.PlLllses10CGfun=function(CLC,t0,pe){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=8)#Pl:
  for (t in 1:59) {
    t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    #left:
    CI.PlLl[t,1]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6+
      CLC$coefficients["Pl:time2:DL"]*t2+CLC$coefficients["Pl:time3:DL"]*t3+CLC$coefficients["Pl:time4:DL"]*t4+CLC$coefficients["Pl:time5:DL"]*t5+CLC$coefficients["Pl:time6:DL"]*t6-
      (CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6+
         CLC$coefficients["Ll:time2:DL"]*t2+CLC$coefficients["Ll:time3:DL"]*t3+CLC$coefficients["Ll:time4:DL"]*t4+CLC$coefficients["Ll:time5:DL"]*t5+CLC$coefficients["Ll:time6:DL"]*t6)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      t2^2*vcov(CLC)["Pl:time2:DL","Pl:time2:DL"]+t3^2*vcov(CLC)["Pl:time3:DL","Pl:time3:DL"]+t4^2*vcov(CLC)["Pl:time4:DL","Pl:time4:DL"]+t5^2*vcov(CLC)["Pl:time5:DL","Pl:time5:DL"]+t6^2*vcov(CLC)["Pl:time6:DL","Pl:time6:DL"]+
      1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]+
      t2^2*vcov(CLC)["Ll:time2:DL","Ll:time2:DL"]+t3^2*vcov(CLC)["Ll:time3:DL","Ll:time3:DL"]+t4^2*vcov(CLC)["Ll:time4:DL","Ll:time4:DL"]+t5^2*vcov(CLC)["Ll:time5:DL","Ll:time5:DL"]+t6^2*vcov(CLC)["Ll:time6:DL","Ll:time6:DL"]-
      2*1*1*vcov(CLC)["Pl_ISL","Ll_ISL"]+2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6"]+
      2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2:DL"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2:DL"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3:DL"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3:DL"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4:DL"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4:DL"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5:DL"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5:DL"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6:DL"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6:DL"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2:DL"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2:DL"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3:DL"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3:DL"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4:DL"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4:DL"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5:DL"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5:DL"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6:DL"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6:DL"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6"]+
      2*t2*t2*vcov(CLC)["Pl:time2","Pl:time2:DL"]-2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2:DL"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3:DL"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3:DL"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4:DL"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4:DL"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5:DL"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5:DL"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6:DL"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6:DL"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]-
      2*t2*t2*vcov(CLC)["Ll:time2","Pl:time2:DL"]+2*t2*t2*vcov(CLC)["Ll:time2","Ll:time2:DL"]-2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3:DL"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3:DL"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4:DL"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4:DL"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5:DL"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5:DL"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6:DL"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]+
      2*t3*t2*vcov(CLC)["Pl:time3","Pl:time2:DL"]-2*t3*t2*vcov(CLC)["Pl:time3","Ll:time2:DL"]+2*t3*t3*vcov(CLC)["Pl:time3","Pl:time3:DL"]-2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t3*t2*vcov(CLC)["Ll:time3","Pl:time2:DL"]+2*t3*t2*vcov(CLC)["Ll:time3","Ll:time2:DL"]-2*t3*t3*vcov(CLC)["Ll:time3","Pl:time3:DL"]+2*t3*t3*vcov(CLC)["Ll:time3","Ll:time3:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]+
      2*t4*t2*vcov(CLC)["Pl:time4","Pl:time2:DL"]-2*t4*t2*vcov(CLC)["Pl:time4","Ll:time2:DL"]+2*t4*t3*vcov(CLC)["Pl:time4","Pl:time3:DL"]-2*t4*t3*vcov(CLC)["Pl:time4","Ll:time3:DL"]+
      2*t4*t4*vcov(CLC)["Pl:time4","Pl:time4:DL"]-2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t4*t2*vcov(CLC)["Ll:time4","Pl:time2:DL"]+2*t4*t2*vcov(CLC)["Ll:time4","Ll:time2:DL"]-2*t4*t3*vcov(CLC)["Ll:time4","Pl:time3:DL"]+2*t4*t3*vcov(CLC)["Ll:time4","Ll:time3:DL"]-
      2*t4*t4*vcov(CLC)["Ll:time4","Pl:time4:DL"]+2*t4*t4*vcov(CLC)["Ll:time4","Ll:time4:DL"]-2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]+
      2*t5*t2*vcov(CLC)["Pl:time5","Pl:time2:DL"]-2*t5*t2*vcov(CLC)["Pl:time5","Ll:time2:DL"]+2*t5*t3*vcov(CLC)["Pl:time5","Pl:time3:DL"]-2*t5*t3*vcov(CLC)["Pl:time5","Ll:time3:DL"]+
      2*t5*t4*vcov(CLC)["Pl:time5","Pl:time4:DL"]-2*t5*t4*vcov(CLC)["Pl:time5","Ll:time4:DL"]+2*t5*t5*vcov(CLC)["Pl:time5","Pl:time5:DL"]-2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t5*t2*vcov(CLC)["Ll:time5","Pl:time2:DL"]+2*t5*t2*vcov(CLC)["Ll:time5","Ll:time2:DL"]-2*t5*t3*vcov(CLC)["Ll:time5","Pl:time3:DL"]+2*t5*t3*vcov(CLC)["Ll:time5","Ll:time3:DL"]-
      2*t5*t4*vcov(CLC)["Ll:time5","Pl:time4:DL"]+2*t5*t4*vcov(CLC)["Ll:time5","Ll:time4:DL"]-2*t5*t5*vcov(CLC)["Ll:time5","Pl:time5:DL"]+2*t5*t5*vcov(CLC)["Ll:time5","Ll:time5:DL"]-2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]+
      2*t6*t2*vcov(CLC)["Pl:time6","Pl:time2:DL"]-2*t6*t2*vcov(CLC)["Pl:time6","Ll:time2:DL"]+2*t6*t3*vcov(CLC)["Pl:time6","Pl:time3:DL"]-2*t6*t3*vcov(CLC)["Pl:time6","Ll:time3:DL"]+
      2*t6*t4*vcov(CLC)["Pl:time6","Pl:time4:DL"]-2*t6*t4*vcov(CLC)["Pl:time6","Ll:time4:DL"]+2*t6*t5*vcov(CLC)["Pl:time6","Pl:time5:DL"]-2*t6*t5*vcov(CLC)["Pl:time6","Ll:time5:DL"]+2*t6*t6*vcov(CLC)["Pl:time6","Pl:time6:DL"]-2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6:DL"]-
      2*t6*t2*vcov(CLC)["Ll:time6","Pl:time2:DL"]+2*t6*t2*vcov(CLC)["Ll:time6","Ll:time2:DL"]-2*t6*t3*vcov(CLC)["Ll:time6","Pl:time3:DL"]+2*t6*t3*vcov(CLC)["Ll:time6","Ll:time3:DL"]-
      2*t6*t4*vcov(CLC)["Ll:time6","Pl:time4:DL"]+2*t6*t4*vcov(CLC)["Ll:time6","Ll:time4:DL"]-2*t6*t5*vcov(CLC)["Ll:time6","Pl:time5:DL"]+2*t6*t5*vcov(CLC)["Ll:time6","Ll:time5:DL"]-2*t6*t6*vcov(CLC)["Ll:time6","Pl:time6:DL"]+2*t6*t6*vcov(CLC)["Ll:time6","Ll:time6:DL"]-
      2*t2*t2*vcov(CLC)["Pl:time2:DL","Ll:time2:DL"]+2*t2*t3*vcov(CLC)["Pl:time2:DL","Pl:time3:DL"]-2*t2*t3*vcov(CLC)["Pl:time2:DL","Ll:time3:DL"]+
      2*t2*t4*vcov(CLC)["Pl:time2:DL","Pl:time4:DL"]-2*t2*t4*vcov(CLC)["Pl:time2:DL","Ll:time4:DL"]+2*t2*t5*vcov(CLC)["Pl:time2:DL","Pl:time5:DL"]-2*t2*t5*vcov(CLC)["Pl:time2:DL","Ll:time5:DL"]+2*t2*t6*vcov(CLC)["Pl:time2:DL","Pl:time6:DL"]-2*t2*t6*vcov(CLC)["Pl:time2:DL","Ll:time6:DL"]-
      2*t2*t3*vcov(CLC)["Ll:time2:DL","Pl:time3:DL"]+2*t2*t3*vcov(CLC)["Ll:time2:DL","Ll:time3:DL"]-
      2*t2*t4*vcov(CLC)["Ll:time2:DL","Pl:time4:DL"]+2*t2*t4*vcov(CLC)["Ll:time2:DL","Ll:time4:DL"]-2*t2*t5*vcov(CLC)["Ll:time2:DL","Pl:time5:DL"]+2*t2*t5*vcov(CLC)["Ll:time2:DL","Ll:time5:DL"]-2*t2*t6*vcov(CLC)["Ll:time2:DL","Pl:time6:DL"]+2*t2*t6*vcov(CLC)["Ll:time2:DL","Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3:DL","Ll:time3:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3:DL","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3:DL","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3:DL","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3:DL","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3:DL","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3:DL","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3:DL","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["Ll:time3:DL","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["Ll:time3:DL","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["Ll:time3:DL","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["Ll:time3:DL","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["Ll:time3:DL","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4:DL","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4:DL","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4:DL","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4:DL","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4:DL","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4:DL","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4:DL","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4:DL","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4:DL","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5:DL","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5:DL","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5:DL","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5:DL","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5:DL","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6:DL","Ll:time6:DL"]
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
    #right:
    CI.PlLl[t,5]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6-
      (CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6)#fitted values
    CI.PlLl[t,6]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]-
      2*1*1*vcov(CLC)["Pl_ISL","Ll_ISL"]+2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]
    CI.PlLl[t,7]=CI.PlLl[t,5]-qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI lower
    CI.PlLl[t,8]=CI.PlLl[t,5]+qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  if (pe==1) {CI.PlLl=CI.PlLl[1:(10+t0),]}
  if (pe==2) {CI.PlLl=CI.PlLl[(11+t0):(20+t0),]}
  if (pe==3) {CI.PlLl=CI.PlLl[(21+t0):(30+t0),]}
  if (pe==4) {CI.PlLl=CI.PlLl[(31+t0):(40+t0),]}
  if (pe==5) {CI.PlLl=CI.PlLl[(41+t0):(50+t0),]}
  if (pe==6) {CI.PlLl=CI.PlLl[(51+t0):59,]}
  CI.PlLl
}#wo Pl:time1:DL,Ll:time1:DL

#Z-test functions:
ZtestfunT12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2)]-CLC$coefficients[paste0("Ll:time",2)]#mean
  v=vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2)]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunTD12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2,":DL")]-CLC$coefficients[paste0("Ll:time",2,":DL")]#mean
  v=vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Pl:time",2,":DL")]+vcov(CLC)[paste0("Ll:time",2,":DL"),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Ll:time",2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunD12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2)]-CLC$coefficients[paste0("Ll:time",2)]+
    CLC$coefficients[paste0("Pl:time",2,":DL")]-CLC$coefficients[paste0("Ll:time",2,":DL")]#mean
  v=vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2)]+
    vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Pl:time",2,":DL")]+vcov(CLC)[paste0("Ll:time",2,":DL"),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2)]+2*vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",2),paste0("Pl:time",2,":DL")]+2*vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Ll:time",2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunT=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunTD=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1,":DL")]-CLC$coefficients[paste0("Ll:time",per1,":DL")]-
        CLC$coefficients[paste0("Pl:time",per2,":DL")]+CLC$coefficients[paste0("Ll:time",per2,":DL")])#mean
  v=vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per1,":DL")]+vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per1,":DL")]+
    vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Pl:time",per2,":DL")]+vcov(CLC)[paste0("Ll:time",per2,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2,":DL")]-2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Ll:time",per2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunD=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]+
        CLC$coefficients[paste0("Pl:time",per1,":DL")]-CLC$coefficients[paste0("Ll:time",per1,":DL")]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)]-
        CLC$coefficients[paste0("Pl:time",per2,":DL")]+CLC$coefficients[paste0("Ll:time",per2,":DL")])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per1,":DL")]+vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per1,":DL")]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]+
    vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Pl:time",per2,":DL")]+vcov(CLC)[paste0("Ll:time",per2,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]+2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per1,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1,":DL")]+2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2)]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2)]-
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per2),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Ll:time",per2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}

#time variables:
t0=0#starting value for thresholds (-4,-2,0,2,4)
de$time1=ifelse(de$time<=10+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regression:
sort(unique(de$Ey[de$DL==1]))#full coverage DL, hence full interactions
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
sort(unique(de$Ey[de$DL==0]))#full coverage non DL, hence full interactions
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
sort(unique(de$Es[de$DL==1]))
```

```
## Error in de$Es: object of type 'closure' is not subsettable
```

``` r
CLC_lses10_EU=clogit(Va ~ Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                        Pl:time2:DL+Ll:time2:DL+Pl:time3:DL+Ll:time3:DL+Pl:time4:DL+Ll:time4:DL+Pl:time5:DL+Ll:time5:DL+Pl:time6:DL+Ll:time6:DL+
                        +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                      +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time2 + Ll:time2 + Pl:time3 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_lses10_EU$coefficients)[names(CLC_lses10_EU$coefficients)=="time2:Ll"]="Ll:time2"
```

```
## Error: object 'CLC_lses10_EU' not found
```

``` r
names(CLC_lses10_EU$coefficients)[names(CLC_lses10_EU$coefficients)=="time2:Ll:DL"]="Ll:time2:DL"
```

```
## Error: object 'CLC_lses10_EU' not found
```

``` r
##Table H1## and ##Table I16##
#hypothesis testing:
stargazer(CLC_lses10_EU)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
#drop EU (DL==0):
ZtestfunT12(CLC_lses10_EU)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
ZtestfunT(CLC_lses10_EU,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
ZtestfunT(CLC_lses10_EU,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
ZtestfunT(CLC_lses10_EU,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
ZtestfunT(CLC_lses10_EU,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
#drop non EU (DL==1):
ZtestfunD12(CLC_lses10_EU)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
ZtestfunD(CLC_lses10_EU,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
ZtestfunD(CLC_lses10_EU,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
ZtestfunD(CLC_lses10_EU,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
ZtestfunD(CLC_lses10_EU,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
#difference in drop between non EU and EU (DL==1 vs DL==0):
ZtestfunTD12(CLC_lses10_EU)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
ZtestfunTD(CLC_lses10_EU,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
ZtestfunTD(CLC_lses10_EU,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
ZtestfunTD(CLC_lses10_EU,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
ZtestfunTD(CLC_lses10_EU,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_EU' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses10_EU.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.84)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.84-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_EU,0,1)) +#(high)
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_EU,0,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_EU,0,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_EU,0,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_EU,0,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_EU,0,6)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_EU,0,1)) +#(low)
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_EU,0,2)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_EU,0,3)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_EU,0,4)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_EU,0,5)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_EU,0,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


#ANALYSIS MARGINAL EFFECTS:----

#DEU_1998(#6) versus DEU_2013(#6):
#(what would have happened in 2013 with the weights of 1998)

#dummies for election-choice FE:
sort(unique(de$Esalt[de$Es=="DEU_1998"]))
```

```
## Error in de$Esalt: object of type 'closure' is not subsettable
```

``` r
#"DEU_19981" "DEU_19982" "DEU_19983" "DEU_19984" "DEU_19985" "DEU_19986"
sort(unique(de$Esalt[de$Es=="DEU_2013"]))
```

```
## Error in de$Esalt: object of type 'closure' is not subsettable
```

``` r
#"DEU_20131" "DEU_20132" "DEU_20133" "DEU_20134" "DEU_20135" "DEU_20136"
de$D981=ifelse(I(de$Esalt=="DEU_19981")==T,1,0)
```

```
## Error in de$Esalt: object of type 'closure' is not subsettable
```

``` r
de$D982=ifelse(I(de$Esalt=="DEU_19982")==T,1,0)
```

```
## Error in de$Esalt: object of type 'closure' is not subsettable
```

``` r
de$D983=ifelse(I(de$Esalt=="DEU_19983")==T,1,0)
```

```
## Error in de$Esalt: object of type 'closure' is not subsettable
```

``` r
de$D984=ifelse(I(de$Esalt=="DEU_19984")==T,1,0)
```

```
## Error in de$Esalt: object of type 'closure' is not subsettable
```

``` r
de$D985=ifelse(I(de$Esalt=="DEU_19985")==T,1,0)
```

```
## Error in de$Esalt: object of type 'closure' is not subsettable
```

``` r
de$D986=ifelse(I(de$Esalt=="DEU_19986")==T,1,0)
```

```
## Error in de$Esalt: object of type 'closure' is not subsettable
```

``` r
de$D131=ifelse(I(de$Esalt=="DEU_20131")==T,1,0)
```

```
## Error in de$Esalt: object of type 'closure' is not subsettable
```

``` r
de$D132=ifelse(I(de$Esalt=="DEU_20132")==T,1,0)
```

```
## Error in de$Esalt: object of type 'closure' is not subsettable
```

``` r
de$D133=ifelse(I(de$Esalt=="DEU_20133")==T,1,0)
```

```
## Error in de$Esalt: object of type 'closure' is not subsettable
```

``` r
de$D134=ifelse(I(de$Esalt=="DEU_20134")==T,1,0)
```

```
## Error in de$Esalt: object of type 'closure' is not subsettable
```

``` r
de$D135=ifelse(I(de$Esalt=="DEU_20135")==T,1,0)
```

```
## Error in de$Esalt: object of type 'closure' is not subsettable
```

``` r
de$D136=ifelse(I(de$Esalt=="DEU_20136")==T,1,0)
```

```
## Error in de$Esalt: object of type 'closure' is not subsettable
```

``` r
#regressions:
CLC_me_98=clogit(Va ~ Pl+Ll+D981+D982+D983+D984+D985+D986+strata(chid)
                 , robust=T, data=de[de$Es=="DEU_1998",], method="efron")
```

```
## Error in de$Es: object of type 'closure' is not subsettable
```

``` r
CLC_me_13=clogit(Va ~ Pl+Ll+D131+D132+D133+D134+D135+D136+strata(chid)
                 , robust=T, data=de[de$Es=="DEU_2013",], method="efron")
```

```
## Error in de$Es: object of type 'closure' is not subsettable
```

``` r
#predicted vote:
de$FEec=ifelse(de$alt==1, CLC_me_13$coefficients[3],#code fixed effects variable
               ifelse(de$alt==2, CLC_me_13$coefficients[4],
                      ifelse(de$alt==3, CLC_me_13$coefficients[5],
                             ifelse(de$alt==4, CLC_me_13$coefficients[6],0))))
```

```
## Error in de$alt: object of type 'closure' is not subsettable
```

``` r
de$Prnum=exp(CLC_me_13$coefficients[1]*de$Pl+CLC_me_13$coefficients[2]*de$Ll+de$FEec)#numerator for Pr
```

```
## Error in eval(expr, envir, enclos): object 'CLC_me_13' not found
```

``` r
de=de %>% group_by(chid) %>% mutate(Prden=sum(Prnum,na.rm=T))#denominator for Pr
```

```
## Error in UseMethod("group_by"): no applicable method for 'group_by' applied to an object of class "function"
```

``` r
de$Pr=de$Prnum/de$Prden#individual predicted Pr
```

```
## Error in de$Prnum: object of type 'closure' is not subsettable
```

``` r
sum(de$Pr[de$Es=="DEU_2013"&de$alt==1],na.rm=T)#cumulative Pr == predicted vote
```

```
## Error in de$Pr: object of type 'closure' is not subsettable
```

``` r
sum(de$Pr[de$Es=="DEU_2013"&de$alt==2],na.rm=T)
```

```
## Error in de$Pr: object of type 'closure' is not subsettable
```

``` r
sum(de$Pr[de$Es=="DEU_2013"&de$alt==3],na.rm=T)
```

```
## Error in de$Pr: object of type 'closure' is not subsettable
```

``` r
sum(de$Pr[de$Es=="DEU_2013"&de$alt==4],na.rm=T)
```

```
## Error in de$Pr: object of type 'closure' is not subsettable
```

``` r
sum(de$Pr[de$Es=="DEU_2013"&de$alt==5],na.rm=T)
```

```
## Error in de$Pr: object of type 'closure' is not subsettable
```

``` r
sum(de$Pr[de$Es=="DEU_2013"&de$alt==6],na.rm=T)
```

```
## Error in de$Pr: object of type 'closure' is not subsettable
```

``` r
table(de$alt[de$Es=="DEU_2013"&de$Va==T])#reported vote
```

```
## Error in de$alt: object of type 'closure' is not subsettable
```

``` r
#ok, predicted vote == reported vote, Pr calculus is correct!

#counterfactual vote:
de$PrnumCF=exp(CLC_me_98$coefficients[1]*de$Pl+CLC_me_98$coefficients[2]*de$Ll+de$FEec)#numerator for Pr
```

```
## Error in eval(expr, envir, enclos): object 'CLC_me_98' not found
```

``` r
de=de %>% group_by(chid) %>% mutate(PrdenCF=sum(PrnumCF,na.rm=T))#denominator for Pr
```

```
## Error in UseMethod("group_by"): no applicable method for 'group_by' applied to an object of class "function"
```

``` r
de$PrCF=de$PrnumCF/de$PrdenCF#individual predicted Pr
```

```
## Error in de$PrnumCF: object of type 'closure' is not subsettable
```

``` r
sum(de$PrCF[de$Es=="DEU_2013"&de$alt==1],na.rm=T)#cumulative Pr == predicted vote
```

```
## Error in de$PrCF: object of type 'closure' is not subsettable
```

``` r
sum(de$PrCF[de$Es=="DEU_2013"&de$alt==2],na.rm=T)
```

```
## Error in de$PrCF: object of type 'closure' is not subsettable
```

``` r
sum(de$PrCF[de$Es=="DEU_2013"&de$alt==3],na.rm=T)
```

```
## Error in de$PrCF: object of type 'closure' is not subsettable
```

``` r
sum(de$PrCF[de$Es=="DEU_2013"&de$alt==4],na.rm=T)
```

```
## Error in de$PrCF: object of type 'closure' is not subsettable
```

``` r
sum(de$PrCF[de$Es=="DEU_2013"&de$alt==5],na.rm=T)
```

```
## Error in de$PrCF: object of type 'closure' is not subsettable
```

``` r
sum(de$PrCF[de$Es=="DEU_2013"&de$alt==6],na.rm=T)
```

```
## Error in de$PrCF: object of type 'closure' is not subsettable
```

``` r
#change (ratio) in vote:
sum(de$PrCF[de$Es=="DEU_2013"&de$alt==1],na.rm=T)/sum(de$Pr[de$Es=="DEU_2013"&de$alt==1],na.rm=T)#0.907
```

```
## Error in de$PrCF: object of type 'closure' is not subsettable
```

``` r
sum(de$PrCF[de$Es=="DEU_2013"&de$alt==2],na.rm=T)/sum(de$Pr[de$Es=="DEU_2013"&de$alt==2],na.rm=T)#1.004
```

```
## Error in de$PrCF: object of type 'closure' is not subsettable
```

``` r
sum(de$PrCF[de$Es=="DEU_2013"&de$alt==3],na.rm=T)/sum(de$Pr[de$Es=="DEU_2013"&de$alt==3],na.rm=T)#1.067
```

```
## Error in de$PrCF: object of type 'closure' is not subsettable
```

``` r
sum(de$PrCF[de$Es=="DEU_2013"&de$alt==4],na.rm=T)/sum(de$Pr[de$Es=="DEU_2013"&de$alt==4],na.rm=T)#1.107
```

```
## Error in de$PrCF: object of type 'closure' is not subsettable
```

``` r
sum(de$PrCF[de$Es=="DEU_2013"&de$alt==5],na.rm=T)/sum(de$Pr[de$Es=="DEU_2013"&de$alt==5],na.rm=T)#1.633
```

```
## Error in de$PrCF: object of type 'closure' is not subsettable
```

``` r
#counterfactual vote share:
#CDU/CSU (34.1+7.4) 41.5 original vote share * 0.907 change in vote share = 37.640
#SPD 25.7 * 1.004 = 25.802
#DIE LINKE 8.6 * 1.067 = 9.176
#GRUENE 8.4 * 1.107 = 9.298
#FDP 4.8 * 1.633 = 7.838

#counterfactual seat share:
#tot vote share parties >5%: 37.640+25.802+9.176+9.298+7.838=89.754
#CDU/CSU 37.640/89.754 = 0.419
#SPD 25.802/89.754 = 0.287
#DIE LINKE 9.176/89.754 = 0.102
#GRUENE 9.298/89.754 = 0.103
#FDP 7.838/89.754 = 0.087
#govt CDU/CSU + FDP = 0.419 + 0.087 = 0.506
# (in the parliament = 0.506*631seats = 319 vs 316 majority)
# (NB not considering possible difference in overhang and leveling seats due to the FDP gaining seats)


#ALTERNATIVE SPECIFICATIONS SPLINE TWO PERIODS:----

#confidence interval functions:
CI.PlLlsesfunCTY=function(CLC,tr,cty){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=4)#Pl:
  for (t in 1:59) {
    t1=pmin(t,tr)
    t2=pmax(tr,t)
    CI.PlLl[t,1]=CLC$coefficients[paste0("Pl_",cty)]+CLC$coefficients["Pl:time1"]*t1+CLC$coefficients["Pl:time2"]*t2-
      (CLC$coefficients[paste0("Ll_",cty)]+CLC$coefficients["Ll:time1"]*t1+CLC$coefficients["Ll:time2"]*t2)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)[paste0("Pl_",cty),paste0("Pl_",cty)]+t1^2*vcov(CLC)["Pl:time1","Pl:time1"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+1*vcov(CLC)[paste0("Ll_",cty),paste0("Ll_",cty)]+t1^2*vcov(CLC)["Ll:time1","Ll:time1"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+
      2*t1*vcov(CLC)[paste0("Pl_",cty),"Pl:time1"]+2*t2*vcov(CLC)[paste0("Pl_",cty),"Pl:time2"]-2*vcov(CLC)[paste0("Pl_",cty),paste0("Ll_",cty)]-2*t1*vcov(CLC)[paste0("Pl_",cty),"Ll:time1"]-2*t2*vcov(CLC)[paste0("Pl_",cty),"Ll:time2"]+
      2*t1*t2*vcov(CLC)["Pl:time1","Pl:time2"]-2*t1*vcov(CLC)[paste0("Ll_",cty),"Pl:time1"]-2*t1^2*vcov(CLC)["Pl:time1","Ll:time1"]-2*t1*t2*vcov(CLC)["Pl:time1","Ll:time2"]-
      2*t2*vcov(CLC)[paste0("Ll_",cty),"Pl:time2"]-2*t1*t2*vcov(CLC)["Ll:time1","Pl:time2"]-2*t2^2*vcov(CLC)["Pl:time2","Ll:time2"]+
      2*t1*vcov(CLC)[paste0("Ll_",cty),"Ll:time1"]+2*t2*vcov(CLC)[paste0("Ll_",cty),"Ll:time2"]+
      2*t1*t2*vcov(CLC)["Ll:time1","Ll:time2"]#Variance new
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  CI.PlLl
}#by cty

#regressions:
tr=38
de$time1=pmin(de$time,tr)#spline functions for coefficients the slopes in each segment
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=pmax(tr,de$time)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
CLC_ses=clogit(Va ~ Pl:time1+Ll:time1+Pl:time2+Ll:time2
                  +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                  +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time1 + Ll:time1 + Pl:time2 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_ses$coefficients)[names(CLC_ses$coefficients)=="time1:Ll"]="Ll:time1"
```

```
## Error: object 'CLC_ses' not found
```

``` r
# , weights=Rwc
trCLC_ses=tr#threshold

#list and test countries by average variance:
vaCLC_ses=matrix(NA,nrow=length(sort(unique(de$Ec))),ncol=2)#average variance by country over time
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
for(i in 1:length(sort(unique(de$Ec)))) {#get average variance over time
  vaCLC_ses[i,1]=paste0(sort(unique(de$Ec))[i])
  vaCLC_ses[i,2]=mean(CI.PlLlsesfunCTY(CLC_ses,trCLC_ses,sort(unique(de$Ec))[i])[,2],na.rm=T)
}
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
vaCLC_ses=as.data.frame(vaCLC_ses)
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_ses' not found
```

``` r
vaCLC_ses=vaCLC_ses[order(vaCLC_ses$V2),]
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_ses' not found
```

``` r
vaCLC_ses[9,1]#country with median variance (ISL#wow)
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_ses' not found
```

``` r
vaCLC_ses[,1]#list of countries by variance (small to high)
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_ses' not found
```

``` r
sort(table(ds$Ec),decreasing=T)#list of countries by elections coded (big to low)
```

```
## Error in eval(expr, envir, enclos): object 'ds' not found
```

``` r
#the 9 countries with higher variance are also the 9 with less elections coded!!!


##Table C1## Two-Period Spline
#plots (median cty):
# tikz(paste0("plot_","CLC_ses","_PlLl_ctymed.tex"),width=4, height=3)#plot Pl-Ll:
plot(ggplot(CI.PlLlsesfunCTY(CLC_ses,trCLC_ses,vaCLC_ses[9,1]), aes(x=t,y=V1)) 
     +ggtitle("Two-Period Spline") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) +
       theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
             panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
       geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
       geom_smooth(aes(ymin=V3,ymax=V4),stat="identity", lwd=2) )
```

```
## Error in eval(expr, envir, enclos): object 'CLC_ses' not found
```

``` r
# dev.off()


#ALTERNATIVE SPECIFICATIONS SPLINE THREE PERIODS:----

#confidence interval functions:
CI.PlLlsessfunCTY=function(CLC,tr1,tr2,cty){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=4)#Pl:
  for (t in 1:59) {
    t1=pmin(t,tr1)
    t2=pmax(tr1,pmin(t,tr2))
    t3=pmax(tr2,t)
    CI.PlLl[t,1]=CLC$coefficients[paste0("Pl_",cty)]+CLC$coefficients["Pl:time1"]*t1+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3-
      (CLC$coefficients[paste0("Ll_",cty)]+CLC$coefficients["Ll:time1"]*t1+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)[paste0("Pl_",cty),paste0("Pl_",cty)]+t1^2*vcov(CLC)["Pl:time1","Pl:time1"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+1*vcov(CLC)[paste0("Ll_",cty),paste0("Ll_",cty)]+t1^2*vcov(CLC)["Ll:time1","Ll:time1"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+
      2*t1*vcov(CLC)[paste0("Pl_",cty),"Pl:time1"]+2*t2*vcov(CLC)[paste0("Pl_",cty),"Pl:time2"]+2*t3*vcov(CLC)[paste0("Pl_",cty),"Pl:time3"]-2*vcov(CLC)[paste0("Pl_",cty),paste0("Ll_",cty)]-2*t1*vcov(CLC)[paste0("Pl_",cty),"Ll:time1"]-2*t2*vcov(CLC)[paste0("Pl_",cty),"Ll:time2"]-2*t3*vcov(CLC)[paste0("Pl_",cty),"Ll:time3"]+
      2*t1*t2*vcov(CLC)["Pl:time1","Pl:time2"]+2*t1*t3*vcov(CLC)["Pl:time1","Pl:time3"]-2*t1*vcov(CLC)["Pl:time1",paste0("Ll_",cty)]-2*t1^2*vcov(CLC)["Pl:time1","Ll:time1"]-2*t1*t2*vcov(CLC)["Pl:time1","Ll:time2"]-2*t1*t3*vcov(CLC)["Pl:time1","Ll:time3"]+
      2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*vcov(CLC)["Pl:time2",paste0("Ll_",cty)]-2*t1*t2*vcov(CLC)["Pl:time2","Ll:time1"]-2*t2^2*vcov(CLC)["Pl:time2","Ll:time2"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]-
      2*t3*vcov(CLC)["Pl:time3",paste0("Ll_",cty)]-2*t3*t1*vcov(CLC)["Pl:time3","Ll:time1"]-2*t3*t2*vcov(CLC)["Pl:time3","Ll:time2"]-2*t3^2*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t1*vcov(CLC)[paste0("Ll_",cty),"Ll:time1"]+2*t2*vcov(CLC)[paste0("Ll_",cty),"Ll:time2"]+2*t3*vcov(CLC)[paste0("Ll_",cty),"Ll:time3"]+
      2*t1*t2*vcov(CLC)["Ll:time1","Ll:time2"]+2*t1*t3*vcov(CLC)["Ll:time1","Ll:time3"]+
      2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  CI.PlLl
}

#regressions:
tr1=9
tr2=37
de$time1=pmin(de$time,tr1)#spline functions for coefficients the slopes in each segment
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=pmax(tr1,pmin(de$time,tr2))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=pmax(tr2,de$time)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
CLC_sess=clogit(Va ~ Pl:time1+Ll:time1+Pl:time2+Ll:time2+Pl:time3+Ll:time3
                   +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                   +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time1 + Ll:time1 + Pl:time2 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_sess$coefficients)[names(CLC_sess$coefficients)=="time1:Ll"]="Ll:time1"
```

```
## Error: object 'CLC_sess' not found
```

``` r
tr1CLC_sess=tr1#
tr2CLC_sess=tr2#

#list and test countries by average variance:
vaCLC_sess=matrix(NA,nrow=length(sort(unique(de$Ec))),ncol=2)#average variance by country over time
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
for(i in 1:length(sort(unique(de$Ec)))) {#get average variance over time
  vaCLC_sess[i,1]=paste0(sort(unique(de$Ec))[i])
  vaCLC_sess[i,2]=mean(CI.PlLlsessfunCTY(CLC_sess,tr1CLC_sess,tr2CLC_sess,sort(unique(de$Ec))[i])[,2],na.rm=T)
}
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
vaCLC_sess=as.data.frame(vaCLC_sess)
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_sess' not found
```

``` r
vaCLC_sess=vaCLC_sess[order(vaCLC_sess$V2),]
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_sess' not found
```

``` r
vaCLC_sess[9,1]#country with median variance
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_sess' not found
```

``` r
vaCLC_sess[,1]#list of countries by variance (small to high)#virtually the same than two periods
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_sess' not found
```

``` r
##Table C1## Three-Period Spline
#plots (median cty):
# tikz(paste0("plot_","CLC_sess","_PlLl_ctymed.tex"),width=4, height=3)#plot Pl-Ll:
plot(ggplot(CI.PlLlsessfunCTY(CLC_sess,tr1CLC_sess,tr2CLC_sess,vaCLC_sess[9,1]), aes(x=t,y=V1)) 
     +ggtitle("Three-Period Spline") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) +
       theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
             panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
       geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
       geom_smooth(aes(ymin=V3,ymax=V4),stat="identity", lwd=2) )
```

```
## Error in eval(expr, envir, enclos): object 'CLC_sess' not found
```

``` r
# dev.off()


#ALTERNATIVE SPECIFICATIONS SPLINE FOUR PERIODS:----

#confidence interval functions:
CI.PlLlsesssfunCTY=function(CLC,tr1,tr2,tr3,cty){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=4)#Pl:
  for (t in 1:59) {
    t1=pmin(t,tr1)
    t2=pmax(tr1,pmin(t,tr2))
    t3=pmax(tr2,pmin(t,tr3))
    t4=pmax(tr3,t)
    CI.PlLl[t,1]=CLC$coefficients[paste0("Pl_",cty)]+CLC$coefficients["Pl:time1"]*t1+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4-
      (CLC$coefficients[paste0("Ll_",cty)]+CLC$coefficients["Ll:time1"]*t1+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)[paste0("Pl_",cty),paste0("Pl_",cty)]+t1^2*vcov(CLC)["Pl:time1","Pl:time1"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+1*vcov(CLC)[paste0("Ll_",cty),paste0("Ll_",cty)]+t1^2*vcov(CLC)["Ll:time1","Ll:time1"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+
      2*t1*vcov(CLC)[paste0("Pl_",cty),"Pl:time1"]+2*t2*vcov(CLC)[paste0("Pl_",cty),"Pl:time2"]+2*t3*vcov(CLC)[paste0("Pl_",cty),"Pl:time3"]+2*t4*vcov(CLC)[paste0("Pl_",cty),"Pl:time4"]-2*vcov(CLC)[paste0("Pl_",cty),paste0("Ll_",cty)]-2*t1*vcov(CLC)[paste0("Pl_",cty),"Ll:time1"]-2*t2*vcov(CLC)[paste0("Pl_",cty),"Ll:time2"]-2*t3*vcov(CLC)[paste0("Pl_",cty),"Ll:time3"]-2*t4*vcov(CLC)[paste0("Pl_",cty),"Ll:time4"]+
      2*t1*t2*vcov(CLC)["Pl:time1","Pl:time2"]+2*t1*t3*vcov(CLC)["Pl:time1","Pl:time3"]+2*t1*t4*vcov(CLC)["Pl:time1","Pl:time4"]-2*t1*vcov(CLC)["Pl:time1",paste0("Ll_",cty)]-2*t1^2*vcov(CLC)["Pl:time1","Ll:time1"]-2*t1*t2*vcov(CLC)["Pl:time1","Ll:time2"]-2*t1*t3*vcov(CLC)["Pl:time1","Ll:time3"]-2*t1*t4*vcov(CLC)["Pl:time1","Ll:time4"]+
      2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]+2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*vcov(CLC)["Pl:time2",paste0("Ll_",cty)]-2*t1*t2*vcov(CLC)["Pl:time2","Ll:time1"]-2*t2^2*vcov(CLC)["Pl:time2","Ll:time2"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*vcov(CLC)["Pl:time3",paste0("Ll_",cty)]-2*t3*t1*vcov(CLC)["Pl:time3","Ll:time1"]-2*t3*t2*vcov(CLC)["Pl:time3","Ll:time2"]-2*t3^2*vcov(CLC)["Pl:time3","Ll:time3"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]-
      2*t4*vcov(CLC)["Pl:time4",paste0("Ll_",cty)]-2*t4*t1*vcov(CLC)["Pl:time4","Ll:time1"]-2*t4*t2*vcov(CLC)["Pl:time4","Ll:time2"]-2*t4*t3*vcov(CLC)["Pl:time4","Ll:time3"]-2*t4^2*vcov(CLC)["Pl:time4","Ll:time4"]+
      2*t1*vcov(CLC)[paste0("Ll_",cty),"Ll:time1"]+2*t2*vcov(CLC)[paste0("Ll_",cty),"Ll:time2"]+2*t3*vcov(CLC)[paste0("Ll_",cty),"Ll:time3"]+2*t4*vcov(CLC)[paste0("Ll_",cty),"Ll:time4"]+
      2*t1*t2*vcov(CLC)["Ll:time1","Ll:time2"]+2*t1*t3*vcov(CLC)["Ll:time1","Ll:time3"]+2*t1*t4*vcov(CLC)["Ll:time1","Ll:time4"]+
      2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]+
      2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]#Variance
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  CI.PlLl
}

#regressions:
tr1=13
tr2=14
tr3=37
de$time1=pmin(de$time,tr1)#spline functions for coefficients the slopes in each segment
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=pmax(tr1,pmin(de$time,tr2))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=pmax(tr2,pmin(de$time,tr3))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=pmax(tr3,de$time)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
CLC_sesss=clogit(Va ~ Pl:time1+Ll:time1+Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4
                    +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                    +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time1 + Ll:time1 + Pl:time2 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_sesss$coefficients)[names(CLC_sesss$coefficients)=="time1:Ll"]="Ll:time1"
```

```
## Error: object 'CLC_sesss' not found
```

``` r
tr1CLC_sesss=tr1#
tr2CLC_sesss=tr2#
tr3CLC_sesss=tr3#

#list and test countries by average variance:
vaCLC_sesss=matrix(NA,nrow=length(sort(unique(de$Ec))),ncol=2)#average variance by country over time
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
for(i in 1:length(sort(unique(de$Ec)))) {#get average variance over time
  vaCLC_sesss[i,1]=paste0(sort(unique(de$Ec))[i])
  vaCLC_sesss[i,2]=mean(CI.PlLlsesssfunCTY(CLC_sesss,tr1CLC_sesss,tr2CLC_sesss,tr3CLC_sesss,sort(unique(de$Ec))[i])[,2],na.rm=T)
}
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
vaCLC_sesss=as.data.frame(vaCLC_sesss)
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_sesss' not found
```

``` r
vaCLC_sesss=vaCLC_sesss[order(vaCLC_sesss$V2),]
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_sesss' not found
```

``` r
vaCLC_sesss[9,1]#country with median variance
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_sesss' not found
```

``` r
vaCLC_sesss[,1]#list of countries by variance (small to high)#virtually the same than two periods
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_sesss' not found
```

``` r
##Table C1## Four-Period Spline
#plots:
#median cty:
# tikz(paste0("plot_","CLC_sesss","_PlLl_ctymed.tex"),width=4, height=3)#plot Pl-Ll:
plot(ggplot(CI.PlLlsesssfunCTY(CLC_sesss,tr1CLC_sesss,tr2CLC_sesss,tr3CLC_sesss,vaCLC_sesss[9,1]), aes(x=t,y=V1)) 
     +ggtitle("Four-Period Spline") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) +
       theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
             panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
       geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
       geom_smooth(aes(ymin=V3,ymax=V4),stat="identity", lwd=2) )
```

```
## Error in eval(expr, envir, enclos): object 'CLC_sesss' not found
```

``` r
# dev.off()


#ALTERNATIVE SPECIFICATIONS SPLINE FIVE PERIODS:----

#confidence interval functions:
CI.PlLlsessssfunCTY=function(CLC,tr1,tr2,tr3,tr4,cty){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=4)#Pl:
  for (t in 1:59) {
    t1=pmin(t,tr1)
    t2=pmax(tr1,pmin(t,tr2))
    t3=pmax(tr2,pmin(t,tr3))
    t4=pmax(tr3,pmin(t,tr4))
    t5=pmax(tr4,t)
    CI.PlLl[t,1]=CLC$coefficients[paste0("Pl_",cty)]+CLC$coefficients["Pl:time1"]*t1+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5-
      (CLC$coefficients[paste0("Ll_",cty)]+CLC$coefficients["Ll:time1"]*t1+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)[paste0("Pl_",cty),paste0("Pl_",cty)]+t1^2*vcov(CLC)["Pl:time1","Pl:time1"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+
      1*vcov(CLC)[paste0("Ll_",cty),paste0("Ll_",cty)]+t1^2*vcov(CLC)["Ll:time1","Ll:time1"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]-
      2*1*1*vcov(CLC)[paste0("Pl_",cty),paste0("Ll_",cty)]+2*1*t1*vcov(CLC)[paste0("Pl_",cty),"Pl:time1"]-2*1*t1*vcov(CLC)[paste0("Pl_",cty),"Ll:time1"]+2*1*t2*vcov(CLC)[paste0("Pl_",cty),"Pl:time2"]-2*1*t2*vcov(CLC)[paste0("Pl_",cty),"Ll:time2"]+2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Pl:time3"]-2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Ll:time3"]+
      2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Pl:time4"]-2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Ll:time4"]+2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Pl:time5"]-2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Ll:time5"]-
      2*1*t1*vcov(CLC)[paste0("Ll_",cty),"Pl:time1"]+2*1*t1*vcov(CLC)[paste0("Ll_",cty),"Ll:time1"]-2*1*t2*vcov(CLC)[paste0("Ll_",cty),"Pl:time2"]+2*1*t2*vcov(CLC)[paste0("Ll_",cty),"Ll:time2"]-2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Pl:time3"]+2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Ll:time3"]-
      2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Pl:time4"]+2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Ll:time4"]-2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Pl:time5"]+2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Ll:time5"]-
      2*t1*t1*vcov(CLC)["Pl:time1","Ll:time1"]+2*t1*t2*vcov(CLC)["Pl:time1","Pl:time2"]-2*t1*t2*vcov(CLC)["Pl:time1","Ll:time2"]+2*t1*t3*vcov(CLC)["Pl:time1","Pl:time3"]-2*t1*t3*vcov(CLC)["Pl:time1","Ll:time3"]+
      2*t1*t4*vcov(CLC)["Pl:time1","Pl:time4"]-2*t1*t4*vcov(CLC)["Pl:time1","Ll:time4"]+2*t1*t5*vcov(CLC)["Pl:time1","Pl:time5"]-2*t1*t5*vcov(CLC)["Pl:time1","Ll:time5"]-
      2*t1*t2*vcov(CLC)["Ll:time1","Pl:time2"]+2*t1*t2*vcov(CLC)["Ll:time1","Ll:time2"]-2*t1*t3*vcov(CLC)["Ll:time1","Pl:time3"]+2*t1*t3*vcov(CLC)["Ll:time1","Ll:time3"]-
      2*t1*t4*vcov(CLC)["Ll:time1","Pl:time4"]+2*t1*t4*vcov(CLC)["Ll:time1","Ll:time4"]-2*t1*t5*vcov(CLC)["Ll:time1","Pl:time5"]+2*t1*t5*vcov(CLC)["Ll:time1","Ll:time5"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  CI.PlLl
}

#regressions:
tr1=8
tr2=13
tr3=14
tr4=37
de$time1=pmin(de$time,tr1)#spline functions for coefficients the slopes in each segment
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=pmax(tr1,pmin(de$time,tr2))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=pmax(tr2,pmin(de$time,tr3))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=pmax(tr3,pmin(de$time,tr4))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=pmax(tr4,de$time)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
CLC_sessss=clogit(Va ~ Pl:time1+Ll:time1+Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5
                      +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                      +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time1 + Ll:time1 + Pl:time2 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_sessss$coefficients)[names(CLC_sessss$coefficients)=="time1:Ll"]="Ll:time1"
```

```
## Error: object 'CLC_sessss' not found
```

``` r
tr1CLC_sessss=tr1#
tr2CLC_sessss=tr2#
tr3CLC_sessss=tr3#
tr4CLC_sessss=tr4#

#list and test countries by average variance:
vaCLC_sessss=matrix(NA,nrow=length(sort(unique(de$Ec))),ncol=2)#average variance by country over time
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
for(i in 1:length(sort(unique(de$Ec)))) {#get average variance over time
  vaCLC_sessss[i,1]=paste0(sort(unique(de$Ec))[i])
  vaCLC_sessss[i,2]=mean(CI.PlLlsessssfunCTY(CLC_sessss,tr1CLC_sessss,tr2CLC_sessss,tr3CLC_sessss,tr4CLC_sessss,sort(unique(de$Ec))[i])[,2],na.rm=T)
}
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
vaCLC_sessss=as.data.frame(vaCLC_sessss)
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_sessss' not found
```

``` r
vaCLC_sessss=vaCLC_sessss[order(vaCLC_sessss$V2),]
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_sessss' not found
```

``` r
vaCLC_sessss[9,1]#country with median variance
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_sessss' not found
```

``` r
vaCLC_sessss[,1]#list of countries by variance (small to high)#virtually the same than two periods
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_sessss' not found
```

``` r
##Table C1## Five-Period Spline
#plots:
#median cty:
# tikz(paste0("plot_","CLC_sessss","_PlLl_ctymed.tex"),width=4, height=3)#plot Pl-Ll:
plot(ggplot(CI.PlLlsessssfunCTY(CLC_sessss,tr1CLC_sessss,tr2CLC_sessss,tr3CLC_sessss,tr4CLC_sessss,vaCLC_sessss[9,1]), aes(x=t,y=V1)) 
     +ggtitle("Five-Period Spline") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,1.15)) + scale_y_continuous(expand=c(0,0)) +
       theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
             panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
       geom_histogram(aes(x=Ey,y=((Eyn*(1.15-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
       geom_smooth(aes(ymin=V3,ymax=V4),stat="identity", lwd=2) )
```

```
## Error in eval(expr, envir, enclos): object 'CLC_sessss' not found
```

``` r
# dev.off()


#ALTERNATIVE SPECIFICATIONS SPLINE COEFFICIENTS:----

#Z-test functions:
ZtestfunS=function(CLC,per){
  m=CLC$coefficients[paste0("Pl:time",per)]-CLC$coefficients[paste0("Ll:time",per)]#mean
  v=vcov(CLC)[paste0("Pl:time",per),paste0("Pl:time",per)]+vcov(CLC)[paste0("Ll:time",per),paste0("Ll:time",per)]-
    2*vcov(CLC)[paste0("Pl:time",per),paste0("Ll:time",per)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}


##Table C1## coefficients
#need to put in the table Party - Leader Likability instead than separate coefficients:
ZtestfunS(CLC_ses,1)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_ses' not found
```

``` r
ZtestfunS(CLC_ses,2)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_ses' not found
```

``` r
ZtestfunS(CLC_sess,1)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_sess' not found
```

``` r
ZtestfunS(CLC_sess,2)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_sess' not found
```

``` r
ZtestfunS(CLC_sess,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_sess' not found
```

``` r
ZtestfunS(CLC_sesss,1)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_sesss' not found
```

``` r
ZtestfunS(CLC_sesss,2)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_sesss' not found
```

``` r
ZtestfunS(CLC_sesss,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_sesss' not found
```

``` r
ZtestfunS(CLC_sesss,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_sesss' not found
```

``` r
ZtestfunS(CLC_sessss,1)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_sessss' not found
```

``` r
ZtestfunS(CLC_sessss,2)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_sessss' not found
```

``` r
ZtestfunS(CLC_sessss,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_sessss' not found
```

``` r
ZtestfunS(CLC_sessss,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_sessss' not found
```

``` r
ZtestfunS(CLC_sessss,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_sessss' not found
```

``` r
#ALTERNATIVE SPECIFICATIONS SEGMENT SPLINE AND FULL TABLE:----

#confidence interval functions:
CI.PlLlses10funCTY=function(CLC,t0,cty){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=4)#Pl:
  for (t in 1:59) {
    t1=pmin(t,10+t0)
    t2=pmax(10+t0,pmin(t,20+t0))
    t3=pmax(20+t0,pmin(t,30+t0))
    t4=pmax(30+t0,pmin(t,40+t0))
    t5=pmax(40+t0,pmin(t,50+t0))
    t6=pmax(50+t0,t)
    CI.PlLl[t,1]=CLC$coefficients[paste0("Pl_",cty)]+CLC$coefficients["Pl:time1"]*t1+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6-
      (CLC$coefficients[paste0("Ll_",cty)]+CLC$coefficients["Ll:time1"]*t1+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)[paste0("Pl_",cty),paste0("Pl_",cty)]+t1^2*vcov(CLC)["Pl:time1","Pl:time1"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      1*vcov(CLC)[paste0("Ll_",cty),paste0("Ll_",cty)]+t1^2*vcov(CLC)["Ll:time1","Ll:time1"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]-
      2*1*1*vcov(CLC)[paste0("Pl_",cty),paste0("Ll_",cty)]+2*1*t1*vcov(CLC)[paste0("Pl_",cty),"Pl:time1"]-2*1*t1*vcov(CLC)[paste0("Pl_",cty),"Ll:time1"]+2*1*t2*vcov(CLC)[paste0("Pl_",cty),"Pl:time2"]-2*1*t2*vcov(CLC)[paste0("Pl_",cty),"Ll:time2"]+2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Pl:time3"]-2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Ll:time3"]+
      2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Pl:time4"]-2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Ll:time4"]+2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Pl:time5"]-2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Ll:time5"]+2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Pl:time6"]-2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Ll:time6"]-
      2*1*t1*vcov(CLC)[paste0("Ll_",cty),"Pl:time1"]+2*1*t1*vcov(CLC)[paste0("Ll_",cty),"Ll:time1"]-2*1*t2*vcov(CLC)[paste0("Ll_",cty),"Pl:time2"]+2*1*t2*vcov(CLC)[paste0("Ll_",cty),"Ll:time2"]-2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Pl:time3"]+2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Ll:time3"]-
      2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Pl:time4"]+2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Ll:time4"]-2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Pl:time5"]+2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Ll:time5"]-2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Pl:time6"]+2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Ll:time6"]-
      2*t1*t1*vcov(CLC)["Pl:time1","Ll:time1"]+2*t1*t2*vcov(CLC)["Pl:time1","Pl:time2"]-2*t1*t2*vcov(CLC)["Pl:time1","Ll:time2"]+2*t1*t3*vcov(CLC)["Pl:time1","Pl:time3"]-2*t1*t3*vcov(CLC)["Pl:time1","Ll:time3"]+
      2*t1*t4*vcov(CLC)["Pl:time1","Pl:time4"]-2*t1*t4*vcov(CLC)["Pl:time1","Ll:time4"]+2*t1*t5*vcov(CLC)["Pl:time1","Pl:time5"]-2*t1*t5*vcov(CLC)["Pl:time1","Ll:time5"]+2*t1*t6*vcov(CLC)["Pl:time1","Pl:time6"]-2*t1*t6*vcov(CLC)["Pl:time1","Ll:time6"]-
      2*t1*t2*vcov(CLC)["Ll:time1","Pl:time2"]+2*t1*t2*vcov(CLC)["Ll:time1","Ll:time2"]-2*t1*t3*vcov(CLC)["Ll:time1","Pl:time3"]+2*t1*t3*vcov(CLC)["Ll:time1","Ll:time3"]-
      2*t1*t4*vcov(CLC)["Ll:time1","Pl:time4"]+2*t1*t4*vcov(CLC)["Ll:time1","Ll:time4"]-2*t1*t5*vcov(CLC)["Ll:time1","Pl:time5"]+2*t1*t5*vcov(CLC)["Ll:time1","Ll:time5"]-2*t1*t6*vcov(CLC)["Ll:time1","Pl:time6"]+2*t1*t6*vcov(CLC)["Ll:time1","Ll:time6"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  CI.PlLl
}

#Z-test functions:
ZtestfunS=function(CLC,per){
  m=CLC$coefficients[paste0("Pl:time",per)]-CLC$coefficients[paste0("Ll:time",per)]#mean
  v=vcov(CLC)[paste0("Pl:time",per),paste0("Pl:time",per)]+vcov(CLC)[paste0("Ll:time",per),paste0("Ll:time",per)]-
    2*vcov(CLC)[paste0("Pl:time",per),paste0("Ll:time",per)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}

#time variables:
t0=0#starting value for thresholds (-4,-2,0,2,4)
de$time1=pmin(de$time,10+t0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=pmax(10+t0,pmin(de$time,20+t0))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=pmax(20+t0,pmin(de$time,30+t0))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=pmax(30+t0,pmin(de$time,40+t0))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=pmax(40+t0,pmin(de$time,50+t0))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=pmax(50+t0,de$time)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
CLC_ses10_0=clogit(Va ~ Pl:time1+Ll:time1+Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6
                      +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                      +strata(Esalt) ,robust=T ,data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time1 + Ll:time1 + Pl:time2 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_ses10_0$coefficients)[names(CLC_ses10_0$coefficients)=="time1:Ll"]="Ll:time1"
```

```
## Error: object 'CLC_ses10_0' not found
```

``` r
##Table C2##
#table (hypothesis testing):
stargazer(CLC_ses10_0,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_ses10_0' not found
```

``` r
ZtestfunS(CLC_ses10_0,1)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_ses10_0' not found
```

``` r
ZtestfunS(CLC_ses10_0,2)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_ses10_0' not found
```

``` r
ZtestfunS(CLC_ses10_0,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_ses10_0' not found
```

``` r
ZtestfunS(CLC_ses10_0,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_ses10_0' not found
```

``` r
ZtestfunS(CLC_ses10_0,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_ses10_0' not found
```

``` r
ZtestfunS(CLC_ses10_0,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_ses10_0' not found
```

``` r
#list and test countries by average variance:
vaCLC_ses10_0=matrix(NA,nrow=length(sort(unique(de$Ec))),ncol=2)#average variance by country over time
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
for(i in 1:length(sort(unique(de$Ec)))) {#get average variance over time
  vaCLC_ses10_0[i,1]=paste0(sort(unique(de$Ec))[i])
  vaCLC_ses10_0[i,2]=mean(CI.PlLlses10funCTY(CLC_ses10_0,0,sort(unique(de$Ec))[i])[,2],na.rm=T)
}
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
vaCLC_ses10_0=as.data.frame(vaCLC_ses10_0)
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_ses10_0' not found
```

``` r
vaCLC_ses10_0=vaCLC_ses10_0[order(vaCLC_ses10_0$V2),]
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_ses10_0' not found
```

``` r
vaCLC_ses10_0[9,1]#country with median variance
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_ses10_0' not found
```

``` r
vaCLC_ses10_0[,1]#list of countries by variance (small to high)#virtually the same than two periods
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_ses10_0' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_ses10_0","_PlLl.tex"),width=4, height=3)#plot Pl-Ll:
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLlses10funCTY(CLC_ses10_0,0,sort(unique(de$Ec))[11])) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##Table I12##
##spline table:
stargazer(CLC_ses,CLC_sess,CLC_sesss,CLC_sessss,CLC_ses10_0)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_ses' not found
```

``` r
#THEORY 10Y SEGMENTS - LEFT VOTERS:----

#confidence interval functions:
CI.PlLllses10LRfunCTY=function(CLC,t0,pe,cty){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=8)#Pl:
  for (t in 1:59) {
    t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.PlLl[t,1]=CLC$coefficients[paste0("Pl_",cty)]+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6+
      CLC$coefficients["Pl:time2:DL"]*t2+CLC$coefficients["Pl:time3:DL"]*t3+CLC$coefficients["Pl:time4:DL"]*t4+CLC$coefficients["Pl:time5:DL"]*t5+CLC$coefficients["Pl:time6:DL"]*t6-
      (CLC$coefficients[paste0("Ll_",cty)]+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6+
         CLC$coefficients["Ll:time2:DL"]*t2+CLC$coefficients["Ll:time3:DL"]*t3+CLC$coefficients["Ll:time4:DL"]*t4+CLC$coefficients["Ll:time5:DL"]*t5+CLC$coefficients["Ll:time6:DL"]*t6)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)[paste0("Pl_",cty),paste0("Pl_",cty)]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      t2^2*vcov(CLC)["Pl:time2:DL","Pl:time2:DL"]+t3^2*vcov(CLC)["Pl:time3:DL","Pl:time3:DL"]+t4^2*vcov(CLC)["Pl:time4:DL","Pl:time4:DL"]+t5^2*vcov(CLC)["Pl:time5:DL","Pl:time5:DL"]+t6^2*vcov(CLC)["Pl:time6:DL","Pl:time6:DL"]+
      1*vcov(CLC)[paste0("Ll_",cty),paste0("Ll_",cty)]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]+
      t2^2*vcov(CLC)["Ll:time2:DL","Ll:time2:DL"]+t3^2*vcov(CLC)["Ll:time3:DL","Ll:time3:DL"]+t4^2*vcov(CLC)["Ll:time4:DL","Ll:time4:DL"]+t5^2*vcov(CLC)["Ll:time5:DL","Ll:time5:DL"]+t6^2*vcov(CLC)["Ll:time6:DL","Ll:time6:DL"]-
      2*1*1*vcov(CLC)[paste0("Pl_",cty),paste0("Ll_",cty)]+2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Pl:time3"]-2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Ll:time3"]+
      2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Pl:time4"]-2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Ll:time4"]+2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Pl:time5"]-2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Ll:time5"]+2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Pl:time6"]-2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Ll:time6"]+
      2*1*t2*vcov(CLC)[paste0("Pl_",cty),"Pl:time2:DL"]-2*1*t2*vcov(CLC)[paste0("Pl_",cty),"Ll:time2:DL"]+2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Pl:time3:DL"]-2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Ll:time3:DL"]+
      2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Pl:time4:DL"]-2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Ll:time4:DL"]+2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Pl:time5:DL"]-2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Ll:time5:DL"]+2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Pl:time6:DL"]-2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Ll:time6:DL"]-
      2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Pl:time3"]+2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Ll:time3"]-
      2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Pl:time4"]+2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Ll:time4"]-2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Pl:time5"]+2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Ll:time5"]-2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Pl:time6"]+2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Ll:time6"]-
      2*1*t2*vcov(CLC)[paste0("Ll_",cty),"Pl:time2:DL"]+2*1*t2*vcov(CLC)[paste0("Ll_",cty),"Ll:time2:DL"]-2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Pl:time3:DL"]+2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Ll:time3:DL"]-
      2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Pl:time4:DL"]+2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Ll:time4:DL"]-2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Pl:time5:DL"]+2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Ll:time5:DL"]-2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Pl:time6:DL"]+2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]+
      2*t3*t2*vcov(CLC)["Pl:time3","Pl:time2:DL"]-2*t3*t2*vcov(CLC)["Pl:time3","Ll:time2:DL"]+2*t3*t3*vcov(CLC)["Pl:time3","Pl:time3:DL"]-2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t3*t2*vcov(CLC)["Ll:time3","Pl:time2:DL"]+2*t3*t2*vcov(CLC)["Ll:time3","Ll:time2:DL"]-2*t3*t3*vcov(CLC)["Ll:time3","Pl:time3:DL"]+2*t3*t3*vcov(CLC)["Ll:time3","Ll:time3:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]+
      2*t4*t2*vcov(CLC)["Pl:time4","Pl:time2:DL"]-2*t4*t2*vcov(CLC)["Pl:time4","Ll:time2:DL"]+2*t4*t3*vcov(CLC)["Pl:time4","Pl:time3:DL"]-2*t4*t3*vcov(CLC)["Pl:time4","Ll:time3:DL"]+
      2*t4*t4*vcov(CLC)["Pl:time4","Pl:time4:DL"]-2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t4*t2*vcov(CLC)["Ll:time4","Pl:time2:DL"]+2*t4*t2*vcov(CLC)["Ll:time4","Ll:time2:DL"]-2*t4*t3*vcov(CLC)["Ll:time4","Pl:time3:DL"]+2*t4*t3*vcov(CLC)["Ll:time4","Ll:time3:DL"]-
      2*t4*t4*vcov(CLC)["Ll:time4","Pl:time4:DL"]+2*t4*t4*vcov(CLC)["Ll:time4","Ll:time4:DL"]-2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]+
      2*t5*t2*vcov(CLC)["Pl:time5","Pl:time2:DL"]-2*t5*t2*vcov(CLC)["Pl:time5","Ll:time2:DL"]+2*t5*t3*vcov(CLC)["Pl:time5","Pl:time3:DL"]-2*t5*t3*vcov(CLC)["Pl:time5","Ll:time3:DL"]+
      2*t5*t4*vcov(CLC)["Pl:time5","Pl:time4:DL"]-2*t5*t4*vcov(CLC)["Pl:time5","Ll:time4:DL"]+2*t5*t5*vcov(CLC)["Pl:time5","Pl:time5:DL"]-2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t5*t2*vcov(CLC)["Ll:time5","Pl:time2:DL"]+2*t5*t2*vcov(CLC)["Ll:time5","Ll:time2:DL"]-2*t5*t3*vcov(CLC)["Ll:time5","Pl:time3:DL"]+2*t5*t3*vcov(CLC)["Ll:time5","Ll:time3:DL"]-
      2*t5*t4*vcov(CLC)["Ll:time5","Pl:time4:DL"]+2*t5*t4*vcov(CLC)["Ll:time5","Ll:time4:DL"]-2*t5*t5*vcov(CLC)["Ll:time5","Pl:time5:DL"]+2*t5*t5*vcov(CLC)["Ll:time5","Ll:time5:DL"]-2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]+
      2*t6*t2*vcov(CLC)["Pl:time6","Pl:time2:DL"]-2*t6*t2*vcov(CLC)["Pl:time6","Ll:time2:DL"]+2*t6*t3*vcov(CLC)["Pl:time6","Pl:time3:DL"]-2*t6*t3*vcov(CLC)["Pl:time6","Ll:time3:DL"]+
      2*t6*t4*vcov(CLC)["Pl:time6","Pl:time4:DL"]-2*t6*t4*vcov(CLC)["Pl:time6","Ll:time4:DL"]+2*t6*t5*vcov(CLC)["Pl:time6","Pl:time5:DL"]-2*t6*t5*vcov(CLC)["Pl:time6","Ll:time5:DL"]+2*t6*t6*vcov(CLC)["Pl:time6","Pl:time6:DL"]-2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6:DL"]-
      2*t6*t2*vcov(CLC)["Ll:time6","Pl:time2:DL"]+2*t6*t2*vcov(CLC)["Ll:time6","Ll:time2:DL"]-2*t6*t3*vcov(CLC)["Ll:time6","Pl:time3:DL"]+2*t6*t3*vcov(CLC)["Ll:time6","Ll:time3:DL"]-
      2*t6*t4*vcov(CLC)["Ll:time6","Pl:time4:DL"]+2*t6*t4*vcov(CLC)["Ll:time6","Ll:time4:DL"]-2*t6*t5*vcov(CLC)["Ll:time6","Pl:time5:DL"]+2*t6*t5*vcov(CLC)["Ll:time6","Ll:time5:DL"]-2*t6*t6*vcov(CLC)["Ll:time6","Pl:time6:DL"]+2*t6*t6*vcov(CLC)["Ll:time6","Ll:time6:DL"]-
      2*t2*t2*vcov(CLC)["Pl:time2:DL","Ll:time2:DL"]+2*t2*t3*vcov(CLC)["Pl:time2:DL","Pl:time3:DL"]-2*t2*t3*vcov(CLC)["Pl:time2:DL","Ll:time3:DL"]+
      2*t2*t4*vcov(CLC)["Pl:time2:DL","Pl:time4:DL"]-2*t2*t4*vcov(CLC)["Pl:time2:DL","Ll:time4:DL"]+2*t2*t5*vcov(CLC)["Pl:time2:DL","Pl:time5:DL"]-2*t2*t5*vcov(CLC)["Pl:time2:DL","Ll:time5:DL"]+2*t2*t6*vcov(CLC)["Pl:time2:DL","Pl:time6:DL"]-2*t2*t6*vcov(CLC)["Pl:time2:DL","Ll:time6:DL"]-
      2*t2*t3*vcov(CLC)["Ll:time2:DL","Pl:time3:DL"]+2*t2*t3*vcov(CLC)["Ll:time2:DL","Ll:time3:DL"]-
      2*t2*t4*vcov(CLC)["Ll:time2:DL","Pl:time4:DL"]+2*t2*t4*vcov(CLC)["Ll:time2:DL","Ll:time4:DL"]-2*t2*t5*vcov(CLC)["Ll:time2:DL","Pl:time5:DL"]+2*t2*t5*vcov(CLC)["Ll:time2:DL","Ll:time5:DL"]-2*t2*t6*vcov(CLC)["Ll:time2:DL","Pl:time6:DL"]+2*t2*t6*vcov(CLC)["Ll:time2:DL","Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3:DL","Ll:time3:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3:DL","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3:DL","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3:DL","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3:DL","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3:DL","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3:DL","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3:DL","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["Ll:time3:DL","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["Ll:time3:DL","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["Ll:time3:DL","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["Ll:time3:DL","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["Ll:time3:DL","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4:DL","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4:DL","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4:DL","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4:DL","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4:DL","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4:DL","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4:DL","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4:DL","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4:DL","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5:DL","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5:DL","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5:DL","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5:DL","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5:DL","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6:DL","Ll:time6:DL"]
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
    #right:
    CI.PlLl[t,5]=CLC$coefficients[paste0("Pl_",cty)]+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6-
      (CLC$coefficients[paste0("Ll_",cty)]+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6)#fitted values
    CI.PlLl[t,6]=1*vcov(CLC)[paste0("Pl_",cty),paste0("Pl_",cty)]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      1*vcov(CLC)[paste0("Ll_",cty),paste0("Ll_",cty)]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]-
      2*1*1*vcov(CLC)[paste0("Pl_",cty),paste0("Ll_",cty)]+2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Pl:time3"]-2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Ll:time3"]+
      2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Pl:time4"]-2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Ll:time4"]+2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Pl:time5"]-2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Ll:time5"]+2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Pl:time6"]-2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Ll:time6"]-
      2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Pl:time3"]+2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Ll:time3"]-
      2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Pl:time4"]+2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Ll:time4"]-2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Pl:time5"]+2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Ll:time5"]-2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Pl:time6"]+2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Ll:time6"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]
    CI.PlLl[t,7]=CI.PlLl[t,5]-qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI lower
    CI.PlLl[t,8]=CI.PlLl[t,5]+qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  if (pe==1) {CI.PlLl=CI.PlLl[1:(10+t0),]}
  if (pe==2) {CI.PlLl=CI.PlLl[(11+t0):(20+t0),]}
  if (pe==3) {CI.PlLl=CI.PlLl[(21+t0):(30+t0),]}
  if (pe==4) {CI.PlLl=CI.PlLl[(31+t0):(40+t0),]}
  if (pe==5) {CI.PlLl=CI.PlLl[(41+t0):(50+t0),]}
  if (pe==6) {CI.PlLl=CI.PlLl[(51+t0):59,]}
  CI.PlLl
}

#Z-test functions:
ZtestfunT=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunTD=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1,":DL")]-CLC$coefficients[paste0("Ll:time",per1,":DL")]-
        CLC$coefficients[paste0("Pl:time",per2,":DL")]+CLC$coefficients[paste0("Ll:time",per2,":DL")])#mean
  v=vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per1,":DL")]+vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per1,":DL")]+
    vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Pl:time",per2,":DL")]+vcov(CLC)[paste0("Ll:time",per2,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2,":DL")]-2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Ll:time",per2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunD=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]+
        CLC$coefficients[paste0("Pl:time",per1,":DL")]-CLC$coefficients[paste0("Ll:time",per1,":DL")]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)]-
        CLC$coefficients[paste0("Pl:time",per2,":DL")]+CLC$coefficients[paste0("Ll:time",per2,":DL")])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per1,":DL")]+vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per1,":DL")]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]+
    vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Pl:time",per2,":DL")]+vcov(CLC)[paste0("Ll:time",per2,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]+2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per1,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1,":DL")]+2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2)]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2)]-
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per2),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Ll:time",per2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}


##left-right - 0.25 quantile:
de=de %>% group_by(Es) %>% mutate(LRR25 = quantile(LRR,0.25,na.rm=TRUE))#0.25 quantile by Es (left)
```

```
## Error in UseMethod("group_by"): no applicable method for 'group_by' applied to an object of class "function"
```

``` r
de$DL=ifelse(de$LRR<de$LRR25,1,0)# left # population 1/4,3/4
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
de$DR=ifelse(de$LRR>=de$LRR25,1,0)# right
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
#time variables:
t0=0#starting value for thresholds (-4,-2,0,2,4)
de$time1=ifelse(de$time<=10+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
CLC_lses10_LR25_0=clogit(Va ~ Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                           Pl:time2:DL+Ll:time2:DL+Pl:time3:DL+Ll:time3:DL+Pl:time4:DL+Ll:time4:DL+Pl:time5:DL+Ll:time5:DL+Pl:time6:DL+Ll:time6:DL+
                           +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                         +strata(Esalt), robust=T, data=de[!is.na(de$LRR),], method="efron")#regression
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
names(CLC_lses10_LR25_0$coefficients)[names(CLC_lses10_LR25_0$coefficients)=="time3:Ll"]="Ll:time3"
```

```
## Error: object 'CLC_lses10_LR25_0' not found
```

``` r
names(CLC_lses10_LR25_0$coefficients)[names(CLC_lses10_LR25_0$coefficients)=="time3:Ll:DL"]="Ll:time3:DL"
```

```
## Error: object 'CLC_lses10_LR25_0' not found
```

``` r
##Table 6##
#hypothesis testing:
stargazer(CLC_lses10_LR25_0,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_0' not found
```

``` r
#drop left-quartile voters:
ZtestfunD(CLC_lses10_LR25_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_0' not found
```

``` r
ZtestfunD(CLC_lses10_LR25_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_0' not found
```

``` r
ZtestfunD(CLC_lses10_LR25_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_0' not found
```

``` r
#drop remaining voters:
ZtestfunT(CLC_lses10_LR25_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_0' not found
```

``` r
ZtestfunT(CLC_lses10_LR25_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_0' not found
```

``` r
ZtestfunT(CLC_lses10_LR25_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_0' not found
```

``` r
#difference in drop between left-quartile and remaining voters:
ZtestfunTD(CLC_lses10_LR25_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_0' not found
```

``` r
ZtestfunTD(CLC_lses10_LR25_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_0' not found
```

``` r
ZtestfunTD(CLC_lses10_LR25_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_0' not found
```

``` r
#list and test countries by average variance:
vaCLC_lses10_LR25_0=matrix(NA,nrow=length(sort(unique(de$Ec))),ncol=2)#average variance by country over time
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
for(i in 1:length(sort(unique(de$Ec)))) {#get average variance over time
  vaCLC_lses10_LR25_0[i,1]=paste0(sort(unique(de$Ec))[i])
  vaCLC_lses10_LR25_0[i,2]=mean(CI.PlLllses10LRfunCTY(CLC_lses10_LR25_0,0,4,sort(unique(de$Ec))[i])[,2],na.rm=T)
}
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
vaCLC_lses10_LR25_0=as.data.frame(vaCLC_lses10_LR25_0)
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_lses10_LR25_0' not found
```

``` r
vaCLC_lses10_LR25_0=vaCLC_lses10_LR25_0[order(vaCLC_lses10_LR25_0$V2),]
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_lses10_LR25_0' not found
```

``` r
vaCLC_lses10_LR25_0[9,1]#country with median variance (the same considering each period)
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_lses10_LR25_0' not found
```

``` r
vaCLC_lses10_LR25_0[,1]#list of countries by variance (small to high)#virtually the same than two periods
```

```
## Error in eval(expr, envir, enclos): object 'vaCLC_lses10_LR25_0' not found
```

``` r
#NB: here ISL is not more the median, but I keep it to ave same country for all graphs
#plots (median cty):
# tikz(paste0("plot_","CLC_lses10_LR25_0","_PlLl_ctymed.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyLRR) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_0,0,3,sort(unique(de$Ec))[11])) +#left
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_0,0,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_0,0,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_0,0,6,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_0,0,3,sort(unique(de$Ec))[11])) +#right
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_0,0,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_0,0,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_0,0,6,sort(unique(de$Ec))[11])) )
```

```
## Error in eval(expr, envir, enclos): object 'dyLRR' not found
```

``` r
# dev.off()


##left-right - 0.15 quantile:
de=de %>% group_by(Es) %>% mutate(LRR15 = quantile(LRR,0.15,na.rm=TRUE))#0.333 quantile by Es (left)
```

```
## Error in UseMethod("group_by"): no applicable method for 'group_by' applied to an object of class "function"
```

``` r
de$DL=ifelse(de$LRR<de$LRR15,1,0)# left # population 1/3,2/3
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
de$DR=ifelse(de$LRR>=de$LRR15,1,0)# right
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
#regressions:
CLC_lses10_LR15_0=clogit(Va ~ Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                           Pl:time2:DL+Ll:time2:DL+Pl:time3:DL+Ll:time3:DL+Pl:time4:DL+Ll:time4:DL+Pl:time5:DL+Ll:time5:DL+Pl:time6:DL+Ll:time6:DL+
                           +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                         +strata(Esalt), robust=T, data=de[!is.na(de$LRR),], method="efron")#regression
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
names(CLC_lses10_LR15_0$coefficients)[names(CLC_lses10_LR15_0$coefficients)=="time3:Ll"]="Ll:time3"
```

```
## Error: object 'CLC_lses10_LR15_0' not found
```

``` r
names(CLC_lses10_LR15_0$coefficients)[names(CLC_lses10_LR15_0$coefficients)=="time3:Ll:DL"]="Ll:time3:DL"
```

```
## Error: object 'CLC_lses10_LR15_0' not found
```

``` r
##Table G1##
#hypothesis testing:
stargazer(CLC_lses10_LR15_0,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR15_0' not found
```

``` r
#drop left-quartile voters:
ZtestfunD(CLC_lses10_LR15_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR15_0' not found
```

``` r
ZtestfunD(CLC_lses10_LR15_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR15_0' not found
```

``` r
ZtestfunD(CLC_lses10_LR15_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR15_0' not found
```

``` r
#drop remaining voters:
ZtestfunT(CLC_lses10_LR15_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR15_0' not found
```

``` r
ZtestfunT(CLC_lses10_LR15_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR15_0' not found
```

``` r
ZtestfunT(CLC_lses10_LR15_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR15_0' not found
```

``` r
#difference in drop between left-quartile and remaining voters:
ZtestfunTD(CLC_lses10_LR15_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR15_0' not found
```

``` r
ZtestfunTD(CLC_lses10_LR15_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR15_0' not found
```

``` r
ZtestfunTD(CLC_lses10_LR15_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR15_0' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses10_LR15_0","_PlLl_ctymed.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyLRR) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR15_0,0,3,sort(unique(de$Ec))[11])) +#left
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR15_0,0,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR15_0,0,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR15_0,0,6,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR15_0,0,3,sort(unique(de$Ec))[11])) +#right
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR15_0,0,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR15_0,0,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR15_0,0,6,sort(unique(de$Ec))[11])) )
```

```
## Error in eval(expr, envir, enclos): object 'dyLRR' not found
```

``` r
# dev.off()


##left-right - 0.35 quantile:
de=de %>% group_by(Es) %>% mutate(LRR35 = quantile(LRR,0.35,na.rm=TRUE))#0.333 quantile by Es (left)
```

```
## Error in UseMethod("group_by"): no applicable method for 'group_by' applied to an object of class "function"
```

``` r
de$DL=ifelse(de$LRR<de$LRR35,1,0)# left # population 1/3,2/3
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
de$DR=ifelse(de$LRR>=de$LRR35,1,0)# right
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
#regressions:
CLC_lses10_LR35_0=clogit(Va ~ Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                           Pl:time2:DL+Ll:time2:DL+Pl:time3:DL+Ll:time3:DL+Pl:time4:DL+Ll:time4:DL+Pl:time5:DL+Ll:time5:DL+Pl:time6:DL+Ll:time6:DL+
                           +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                         +strata(Esalt), robust=T, data=de[!is.na(de$LRR),], method="efron")#regression
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
names(CLC_lses10_LR35_0$coefficients)[names(CLC_lses10_LR35_0$coefficients)=="time3:Ll"]="Ll:time3"
```

```
## Error: object 'CLC_lses10_LR35_0' not found
```

``` r
names(CLC_lses10_LR35_0$coefficients)[names(CLC_lses10_LR35_0$coefficients)=="time3:Ll:DL"]="Ll:time3:DL"
```

```
## Error: object 'CLC_lses10_LR35_0' not found
```

``` r
##Table G2##
#hypothesis testing:
stargazer(CLC_lses10_LR35_0,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR35_0' not found
```

``` r
#drop left-quartile voters:
ZtestfunD(CLC_lses10_LR35_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR35_0' not found
```

``` r
ZtestfunD(CLC_lses10_LR35_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR35_0' not found
```

``` r
ZtestfunD(CLC_lses10_LR35_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR35_0' not found
```

``` r
#drop remaining voters:
ZtestfunT(CLC_lses10_LR35_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR35_0' not found
```

``` r
ZtestfunT(CLC_lses10_LR35_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR35_0' not found
```

``` r
ZtestfunT(CLC_lses10_LR35_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR35_0' not found
```

``` r
#difference in drop between left-quartile and remaining voters:
ZtestfunTD(CLC_lses10_LR35_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR35_0' not found
```

``` r
ZtestfunTD(CLC_lses10_LR35_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR35_0' not found
```

``` r
ZtestfunTD(CLC_lses10_LR35_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR35_0' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses10_LR35_0","_PlLl_ctymed.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.35,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyLRR) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR35_0,0,3,sort(unique(de$Ec))[11])) +#left
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR35_0,0,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR35_0,0,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR35_0,0,6,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR35_0,0,3,sort(unique(de$Ec))[11])) +#right
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR35_0,0,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR35_0,0,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR35_0,0,6,sort(unique(de$Ec))[11])) )
```

```
## Error in eval(expr, envir, enclos): object 'dyLRR' not found
```

``` r
# dev.off()


##Table I15##
##table full results:
stargazer(CLC_lses10_LR15_0,CLC_lses10_LR35_0)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR15_0' not found
```

``` r
##THEORY 10Y SEGMENTS - LEFT VOTERS - ALTERNATIVE THRESHOLDS AND FULL REUSLTS TABLE:----

##left-right - 0.25 quantile:
de=de %>% group_by(Es) %>% mutate(LRR25 = quantile(LRR,0.25,na.rm=TRUE))#0.25 quantile by Es (left)
```

```
## Error in UseMethod("group_by"): no applicable method for 'group_by' applied to an object of class "function"
```

``` r
de$DL=ifelse(de$LRR<de$LRR25,1,0)# left # population 1/4,3/4
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
de$DR=ifelse(de$LRR>=de$LRR25,1,0)# right
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
##Table D9##
##starting value for thresholds -4
#time variables:
t0=-4#starting value for thresholds (-4,-2,0,2,4)
de$time1=ifelse(de$time<=10+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
CLC_lses10_LR25_m4=clogit(Va ~ Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                           Pl:time2:DL+Ll:time2:DL+Pl:time3:DL+Ll:time3:DL+Pl:time4:DL+Ll:time4:DL+Pl:time5:DL+Ll:time5:DL+Pl:time6:DL+Ll:time6:DL+
                           +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                         +strata(Esalt), robust=T, data=de[!is.na(de$LRR),], method="efron")#regression
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
names(CLC_lses10_LR25_m4$coefficients)[names(CLC_lses10_LR25_m4$coefficients)=="time3:Ll"]="Ll:time3"
```

```
## Error: object 'CLC_lses10_LR25_m4' not found
```

``` r
names(CLC_lses10_LR25_m4$coefficients)[names(CLC_lses10_LR25_m4$coefficients)=="time3:Ll:DL"]="Ll:time3:DL"
```

```
## Error: object 'CLC_lses10_LR25_m4' not found
```

``` r
#hypothesis testing:
stargazer(CLC_lses10_LR25_m4,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m4' not found
```

``` r
#drop left-quartile voters:
ZtestfunD(CLC_lses10_LR25_m4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m4' not found
```

``` r
ZtestfunD(CLC_lses10_LR25_m4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m4' not found
```

``` r
ZtestfunD(CLC_lses10_LR25_m4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m4' not found
```

``` r
#drop remaining voters:
ZtestfunT(CLC_lses10_LR25_m4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m4' not found
```

``` r
ZtestfunT(CLC_lses10_LR25_m4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m4' not found
```

``` r
ZtestfunT(CLC_lses10_LR25_m4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m4' not found
```

``` r
#difference in drop between left-quartile and remaining voters:
ZtestfunTD(CLC_lses10_LR25_m4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m4' not found
```

``` r
ZtestfunTD(CLC_lses10_LR25_m4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m4' not found
```

``` r
ZtestfunTD(CLC_lses10_LR25_m4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m4' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses10_LR25_m4","_PlLl_ctymed.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyLRR) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m4,-4,3,sort(unique(de$Ec))[11])) +#left
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m4,-4,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m4,-4,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m4,-4,6,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m4,-4,3,sort(unique(de$Ec))[11])) +#right
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m4,-4,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m4,-4,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m4,-4,6,sort(unique(de$Ec))[11])) )
```

```
## Error in eval(expr, envir, enclos): object 'dyLRR' not found
```

``` r
# dev.off()


##starting value for thresholds -2
#time variables:
t0=-2#starting value for thresholds (-4,-2,0,2,4)
de$time1=ifelse(de$time<=10+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
CLC_lses10_LR25_m2=clogit(Va ~ Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                            Pl:time2:DL+Ll:time2:DL+Pl:time3:DL+Ll:time3:DL+Pl:time4:DL+Ll:time4:DL+Pl:time5:DL+Ll:time5:DL+Pl:time6:DL+Ll:time6:DL+
                            +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                          +strata(Esalt), robust=T, data=de[!is.na(de$LRR),], method="efron")#regression
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
names(CLC_lses10_LR25_m2$coefficients)[names(CLC_lses10_LR25_m2$coefficients)=="time3:Ll"]="Ll:time3"
```

```
## Error: object 'CLC_lses10_LR25_m2' not found
```

``` r
names(CLC_lses10_LR25_m2$coefficients)[names(CLC_lses10_LR25_m2$coefficients)=="time3:Ll:DL"]="Ll:time3:DL"
```

```
## Error: object 'CLC_lses10_LR25_m2' not found
```

``` r
#hypothesis testing:
stargazer(CLC_lses10_LR25_m2,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m2' not found
```

``` r
#drop left-quartile voters:
ZtestfunD(CLC_lses10_LR25_m2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m2' not found
```

``` r
ZtestfunD(CLC_lses10_LR25_m2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m2' not found
```

``` r
ZtestfunD(CLC_lses10_LR25_m2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m2' not found
```

``` r
#drop remaining voters:
ZtestfunT(CLC_lses10_LR25_m2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m2' not found
```

``` r
ZtestfunT(CLC_lses10_LR25_m2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m2' not found
```

``` r
ZtestfunT(CLC_lses10_LR25_m2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m2' not found
```

``` r
#difference in drop between left-quartile and remaining voters:
ZtestfunTD(CLC_lses10_LR25_m2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m2' not found
```

``` r
ZtestfunTD(CLC_lses10_LR25_m2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m2' not found
```

``` r
ZtestfunTD(CLC_lses10_LR25_m2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m2' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses10_LR25_m2","_PlLl_ctymed.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyLRR) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m2,-2,3,sort(unique(de$Ec))[11])) +#left
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m2,-2,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m2,-2,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m2,-2,6,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m2,-2,3,sort(unique(de$Ec))[11])) +#right
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m2,-2,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m2,-2,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_m2,-2,6,sort(unique(de$Ec))[11])) )
```

```
## Error in eval(expr, envir, enclos): object 'dyLRR' not found
```

``` r
# dev.off()


##starting value for thresholds 2
#time variables:
t0=2#starting value for thresholds (-4,-2,0,2,4)
de$time1=ifelse(de$time<=10+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
CLC_lses10_LR25_2=clogit(Va ~ Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                            Pl:time2:DL+Ll:time2:DL+Pl:time3:DL+Ll:time3:DL+Pl:time4:DL+Ll:time4:DL+Pl:time5:DL+Ll:time5:DL+Pl:time6:DL+Ll:time6:DL+
                            +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                          +strata(Esalt), robust=T, data=de[!is.na(de$LRR),], method="efron")#regression
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
names(CLC_lses10_LR25_2$coefficients)[names(CLC_lses10_LR25_2$coefficients)=="time3:Ll"]="Ll:time3"
```

```
## Error: object 'CLC_lses10_LR25_2' not found
```

``` r
names(CLC_lses10_LR25_2$coefficients)[names(CLC_lses10_LR25_2$coefficients)=="time3:Ll:DL"]="Ll:time3:DL"
```

```
## Error: object 'CLC_lses10_LR25_2' not found
```

``` r
#hypothesis testing:
stargazer(CLC_lses10_LR25_2,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_2' not found
```

``` r
#drop left-quartile voters:
ZtestfunD(CLC_lses10_LR25_2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_2' not found
```

``` r
ZtestfunD(CLC_lses10_LR25_2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_2' not found
```

``` r
ZtestfunD(CLC_lses10_LR25_2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_2' not found
```

``` r
#drop remaining voters:
ZtestfunT(CLC_lses10_LR25_2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_2' not found
```

``` r
ZtestfunT(CLC_lses10_LR25_2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_2' not found
```

``` r
ZtestfunT(CLC_lses10_LR25_2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_2' not found
```

``` r
#difference in drop between left-quartile and remaining voters:
ZtestfunTD(CLC_lses10_LR25_2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_2' not found
```

``` r
ZtestfunTD(CLC_lses10_LR25_2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_2' not found
```

``` r
ZtestfunTD(CLC_lses10_LR25_2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_2' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses10_LR25_2","_PlLl_ctymed.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyLRR) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_2,2,3,sort(unique(de$Ec))[11])) +#left
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_2,2,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_2,2,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_2,2,6,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_2,2,3,sort(unique(de$Ec))[11])) +#right
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_2,2,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_2,2,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_2,2,6,sort(unique(de$Ec))[11])) )
```

```
## Error in eval(expr, envir, enclos): object 'dyLRR' not found
```

``` r
# dev.off()


##starting value for thresholds 4
#time variables:
t0=4#starting value for thresholds (-4,-2,0,2,4)
de$time1=ifelse(de$time<=10+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
CLC_lses10_LR25_4=clogit(Va ~ Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                            Pl:time2:DL+Ll:time2:DL+Pl:time3:DL+Ll:time3:DL+Pl:time4:DL+Ll:time4:DL+Pl:time5:DL+Ll:time5:DL+Pl:time6:DL+Ll:time6:DL+
                            +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                          +strata(Esalt), robust=T, data=de[!is.na(de$LRR),], method="efron")#regression
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
names(CLC_lses10_LR25_4$coefficients)[names(CLC_lses10_LR25_4$coefficients)=="time3:Ll"]="Ll:time3"
```

```
## Error: object 'CLC_lses10_LR25_4' not found
```

``` r
names(CLC_lses10_LR25_4$coefficients)[names(CLC_lses10_LR25_4$coefficients)=="time3:Ll:DL"]="Ll:time3:DL"
```

```
## Error: object 'CLC_lses10_LR25_4' not found
```

``` r
#hypothesis testing:
stargazer(CLC_lses10_LR25_4,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_4' not found
```

``` r
#drop left-quartile voters:
ZtestfunD(CLC_lses10_LR25_4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_4' not found
```

``` r
ZtestfunD(CLC_lses10_LR25_4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_4' not found
```

``` r
ZtestfunD(CLC_lses10_LR25_4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_4' not found
```

``` r
#drop remaining voters:
ZtestfunT(CLC_lses10_LR25_4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_4' not found
```

``` r
ZtestfunT(CLC_lses10_LR25_4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_4' not found
```

``` r
ZtestfunT(CLC_lses10_LR25_4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_4' not found
```

``` r
#difference in drop between left-quartile and remaining voters:
ZtestfunTD(CLC_lses10_LR25_4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_4' not found
```

``` r
ZtestfunTD(CLC_lses10_LR25_4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_4' not found
```

``` r
ZtestfunTD(CLC_lses10_LR25_4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_4' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses10_LR25_4","_PlLl_ctymed.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyLRR) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_4,4,3,sort(unique(de$Ec))[11])) +#left
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_4,4,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_4,4,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_4,4,6,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_4,4,3,sort(unique(de$Ec))[11])) +#right
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_4,4,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_4,4,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses10_LR25_4,4,6,sort(unique(de$Ec))[11])) )
```

```
## Error in eval(expr, envir, enclos): object 'dyLRR' not found
```

``` r
# dev.off()


##Table I7##
##table full results:
cm4=CLC_lses10_LR25_m4#shorten name for stargazer:
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m4' not found
```

``` r
cm2=CLC_lses10_LR25_m2
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_m2' not found
```

``` r
c0=CLC_lses10_LR25_0
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_0' not found
```

``` r
c2=CLC_lses10_LR25_2
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_2' not found
```

``` r
c4=CLC_lses10_LR25_4
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_LR25_4' not found
```

``` r
stargazer(cm4,cm2,c0,c2,c4)#table
```

```
## Error in eval(expr, envir, enclos): object 'cm4' not found
```

``` r
rm(cm4,cm2,c0,c2,c4)


#THEORY 10Y SEGMENTS - GERMANY:----

#Germany dummy:
de$DL[de$Ec %in% c("DEU")]=1#Germany
```

```
## Error in `*tmp*`$DL: object of type 'closure' is not subsettable
```

``` r
de$DL[!de$Ec %in% c("DEU")]=0#others
```

```
## Error in `*tmp*`$DL: object of type 'closure' is not subsettable
```

``` r
#confidence interval functions:
CI.PlLllses10CGfun=function(CLC,t0,pe){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=8)#Pl:
  for (t in 1:59) {
    t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    #left:
    CI.PlLl[t,1]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6+
      CLC$coefficients["Pl:time2:DL"]*t2+CLC$coefficients["Pl:time3:DL"]*t3+CLC$coefficients["Pl:time4:DL"]*t4+CLC$coefficients["Pl:time5:DL"]*t5+CLC$coefficients["Pl:time6:DL"]*t6-
      (CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6+
         CLC$coefficients["Ll:time2:DL"]*t2+CLC$coefficients["Ll:time3:DL"]*t3+CLC$coefficients["Ll:time4:DL"]*t4+CLC$coefficients["Ll:time5:DL"]*t5+CLC$coefficients["Ll:time6:DL"]*t6)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      t2^2*vcov(CLC)["Pl:time2:DL","Pl:time2:DL"]+t3^2*vcov(CLC)["Pl:time3:DL","Pl:time3:DL"]+t4^2*vcov(CLC)["Pl:time4:DL","Pl:time4:DL"]+t5^2*vcov(CLC)["Pl:time5:DL","Pl:time5:DL"]+t6^2*vcov(CLC)["Pl:time6:DL","Pl:time6:DL"]+
      1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]+
      t2^2*vcov(CLC)["Ll:time2:DL","Ll:time2:DL"]+t3^2*vcov(CLC)["Ll:time3:DL","Ll:time3:DL"]+t4^2*vcov(CLC)["Ll:time4:DL","Ll:time4:DL"]+t5^2*vcov(CLC)["Ll:time5:DL","Ll:time5:DL"]+t6^2*vcov(CLC)["Ll:time6:DL","Ll:time6:DL"]-
      2*1*1*vcov(CLC)["Pl_ISL","Ll_ISL"]+2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6"]+
      2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2:DL"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2:DL"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3:DL"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3:DL"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4:DL"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4:DL"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5:DL"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5:DL"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6:DL"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6:DL"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2:DL"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2:DL"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3:DL"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3:DL"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4:DL"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4:DL"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5:DL"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5:DL"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6:DL"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6:DL"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6"]+
      2*t2*t2*vcov(CLC)["Pl:time2","Pl:time2:DL"]-2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2:DL"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3:DL"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3:DL"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4:DL"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4:DL"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5:DL"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5:DL"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6:DL"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6:DL"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]-
      2*t2*t2*vcov(CLC)["Ll:time2","Pl:time2:DL"]+2*t2*t2*vcov(CLC)["Ll:time2","Ll:time2:DL"]-2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3:DL"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3:DL"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4:DL"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4:DL"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5:DL"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5:DL"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6:DL"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]+
      2*t3*t2*vcov(CLC)["Pl:time3","Pl:time2:DL"]-2*t3*t2*vcov(CLC)["Pl:time3","Ll:time2:DL"]+2*t3*t3*vcov(CLC)["Pl:time3","Pl:time3:DL"]-2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t3*t2*vcov(CLC)["Ll:time3","Pl:time2:DL"]+2*t3*t2*vcov(CLC)["Ll:time3","Ll:time2:DL"]-2*t3*t3*vcov(CLC)["Ll:time3","Pl:time3:DL"]+2*t3*t3*vcov(CLC)["Ll:time3","Ll:time3:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]+
      2*t4*t2*vcov(CLC)["Pl:time4","Pl:time2:DL"]-2*t4*t2*vcov(CLC)["Pl:time4","Ll:time2:DL"]+2*t4*t3*vcov(CLC)["Pl:time4","Pl:time3:DL"]-2*t4*t3*vcov(CLC)["Pl:time4","Ll:time3:DL"]+
      2*t4*t4*vcov(CLC)["Pl:time4","Pl:time4:DL"]-2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t4*t2*vcov(CLC)["Ll:time4","Pl:time2:DL"]+2*t4*t2*vcov(CLC)["Ll:time4","Ll:time2:DL"]-2*t4*t3*vcov(CLC)["Ll:time4","Pl:time3:DL"]+2*t4*t3*vcov(CLC)["Ll:time4","Ll:time3:DL"]-
      2*t4*t4*vcov(CLC)["Ll:time4","Pl:time4:DL"]+2*t4*t4*vcov(CLC)["Ll:time4","Ll:time4:DL"]-2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]+
      2*t5*t2*vcov(CLC)["Pl:time5","Pl:time2:DL"]-2*t5*t2*vcov(CLC)["Pl:time5","Ll:time2:DL"]+2*t5*t3*vcov(CLC)["Pl:time5","Pl:time3:DL"]-2*t5*t3*vcov(CLC)["Pl:time5","Ll:time3:DL"]+
      2*t5*t4*vcov(CLC)["Pl:time5","Pl:time4:DL"]-2*t5*t4*vcov(CLC)["Pl:time5","Ll:time4:DL"]+2*t5*t5*vcov(CLC)["Pl:time5","Pl:time5:DL"]-2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t5*t2*vcov(CLC)["Ll:time5","Pl:time2:DL"]+2*t5*t2*vcov(CLC)["Ll:time5","Ll:time2:DL"]-2*t5*t3*vcov(CLC)["Ll:time5","Pl:time3:DL"]+2*t5*t3*vcov(CLC)["Ll:time5","Ll:time3:DL"]-
      2*t5*t4*vcov(CLC)["Ll:time5","Pl:time4:DL"]+2*t5*t4*vcov(CLC)["Ll:time5","Ll:time4:DL"]-2*t5*t5*vcov(CLC)["Ll:time5","Pl:time5:DL"]+2*t5*t5*vcov(CLC)["Ll:time5","Ll:time5:DL"]-2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]+
      2*t6*t2*vcov(CLC)["Pl:time6","Pl:time2:DL"]-2*t6*t2*vcov(CLC)["Pl:time6","Ll:time2:DL"]+2*t6*t3*vcov(CLC)["Pl:time6","Pl:time3:DL"]-2*t6*t3*vcov(CLC)["Pl:time6","Ll:time3:DL"]+
      2*t6*t4*vcov(CLC)["Pl:time6","Pl:time4:DL"]-2*t6*t4*vcov(CLC)["Pl:time6","Ll:time4:DL"]+2*t6*t5*vcov(CLC)["Pl:time6","Pl:time5:DL"]-2*t6*t5*vcov(CLC)["Pl:time6","Ll:time5:DL"]+2*t6*t6*vcov(CLC)["Pl:time6","Pl:time6:DL"]-2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6:DL"]-
      2*t6*t2*vcov(CLC)["Ll:time6","Pl:time2:DL"]+2*t6*t2*vcov(CLC)["Ll:time6","Ll:time2:DL"]-2*t6*t3*vcov(CLC)["Ll:time6","Pl:time3:DL"]+2*t6*t3*vcov(CLC)["Ll:time6","Ll:time3:DL"]-
      2*t6*t4*vcov(CLC)["Ll:time6","Pl:time4:DL"]+2*t6*t4*vcov(CLC)["Ll:time6","Ll:time4:DL"]-2*t6*t5*vcov(CLC)["Ll:time6","Pl:time5:DL"]+2*t6*t5*vcov(CLC)["Ll:time6","Ll:time5:DL"]-2*t6*t6*vcov(CLC)["Ll:time6","Pl:time6:DL"]+2*t6*t6*vcov(CLC)["Ll:time6","Ll:time6:DL"]-
      2*t2*t2*vcov(CLC)["Pl:time2:DL","Ll:time2:DL"]+2*t2*t3*vcov(CLC)["Pl:time2:DL","Pl:time3:DL"]-2*t2*t3*vcov(CLC)["Pl:time2:DL","Ll:time3:DL"]+
      2*t2*t4*vcov(CLC)["Pl:time2:DL","Pl:time4:DL"]-2*t2*t4*vcov(CLC)["Pl:time2:DL","Ll:time4:DL"]+2*t2*t5*vcov(CLC)["Pl:time2:DL","Pl:time5:DL"]-2*t2*t5*vcov(CLC)["Pl:time2:DL","Ll:time5:DL"]+2*t2*t6*vcov(CLC)["Pl:time2:DL","Pl:time6:DL"]-2*t2*t6*vcov(CLC)["Pl:time2:DL","Ll:time6:DL"]-
      2*t2*t3*vcov(CLC)["Ll:time2:DL","Pl:time3:DL"]+2*t2*t3*vcov(CLC)["Ll:time2:DL","Ll:time3:DL"]-
      2*t2*t4*vcov(CLC)["Ll:time2:DL","Pl:time4:DL"]+2*t2*t4*vcov(CLC)["Ll:time2:DL","Ll:time4:DL"]-2*t2*t5*vcov(CLC)["Ll:time2:DL","Pl:time5:DL"]+2*t2*t5*vcov(CLC)["Ll:time2:DL","Ll:time5:DL"]-2*t2*t6*vcov(CLC)["Ll:time2:DL","Pl:time6:DL"]+2*t2*t6*vcov(CLC)["Ll:time2:DL","Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3:DL","Ll:time3:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3:DL","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3:DL","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3:DL","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3:DL","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3:DL","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3:DL","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3:DL","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["Ll:time3:DL","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["Ll:time3:DL","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["Ll:time3:DL","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["Ll:time3:DL","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["Ll:time3:DL","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4:DL","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4:DL","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4:DL","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4:DL","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4:DL","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4:DL","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4:DL","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4:DL","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4:DL","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5:DL","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5:DL","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5:DL","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5:DL","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5:DL","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6:DL","Ll:time6:DL"]
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
    #right:
    CI.PlLl[t,5]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6-
      (CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6)#fitted values
    CI.PlLl[t,6]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]-
      2*1*1*vcov(CLC)["Pl_ISL","Ll_ISL"]+2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]
    CI.PlLl[t,7]=CI.PlLl[t,5]-qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI lower
    CI.PlLl[t,8]=CI.PlLl[t,5]+qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  if (pe==1) {CI.PlLl=CI.PlLl[1:(10+t0),]}
  if (pe==2) {CI.PlLl=CI.PlLl[(11+t0):(20+t0),]}
  if (pe==3) {CI.PlLl=CI.PlLl[(21+t0):(30+t0),]}
  if (pe==4) {CI.PlLl=CI.PlLl[(31+t0):(40+t0),]}
  if (pe==5) {CI.PlLl=CI.PlLl[(41+t0):(50+t0),]}
  if (pe==6) {CI.PlLl=CI.PlLl[(51+t0):59,]}
  CI.PlLl
}#wo Pl:time1:DL,Ll:time1:DL

#Z-test functions:
ZtestfunT12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2)]-CLC$coefficients[paste0("Ll:time",2)]#mean
  v=vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2)]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunTD12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2,":DL")]-CLC$coefficients[paste0("Ll:time",2,":DL")]#mean
  v=vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Pl:time",2,":DL")]+vcov(CLC)[paste0("Ll:time",2,":DL"),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Ll:time",2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunD12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2)]-CLC$coefficients[paste0("Ll:time",2)]+
    CLC$coefficients[paste0("Pl:time",2,":DL")]-CLC$coefficients[paste0("Ll:time",2,":DL")]#mean
  v=vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2)]+
    vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Pl:time",2,":DL")]+vcov(CLC)[paste0("Ll:time",2,":DL"),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2)]+2*vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",2),paste0("Pl:time",2,":DL")]+2*vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Ll:time",2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunT=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunTD=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1,":DL")]-CLC$coefficients[paste0("Ll:time",per1,":DL")]-
        CLC$coefficients[paste0("Pl:time",per2,":DL")]+CLC$coefficients[paste0("Ll:time",per2,":DL")])#mean
  v=vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per1,":DL")]+vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per1,":DL")]+
    vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Pl:time",per2,":DL")]+vcov(CLC)[paste0("Ll:time",per2,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2,":DL")]-2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Ll:time",per2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunD=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]+
        CLC$coefficients[paste0("Pl:time",per1,":DL")]-CLC$coefficients[paste0("Ll:time",per1,":DL")]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)]-
        CLC$coefficients[paste0("Pl:time",per2,":DL")]+CLC$coefficients[paste0("Ll:time",per2,":DL")])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per1,":DL")]+vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per1,":DL")]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]+
    vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Pl:time",per2,":DL")]+vcov(CLC)[paste0("Ll:time",per2,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]+2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per1,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1,":DL")]+2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2)]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2)]-
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per2),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Ll:time",per2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}

#time variables:
t0=0#starting value for thresholds (-4,-2,0,2,4)
de$time1=ifelse(de$time<=10+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regression:
sort(unique(de$Ey[de$DL==1]))#full coverage DL, hence full interactions
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
sort(unique(de$Ey[de$DL==0]))#full coverage non DL, hence full interactions
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
CLC_lses10_DEU=clogit(Va ~ Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                        Pl:time2:DL+Ll:time2:DL+Pl:time3:DL+Ll:time3:DL+Pl:time4:DL+Ll:time4:DL+Pl:time5:DL+Ll:time5:DL+Pl:time6:DL+Ll:time6:DL+
                        +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                      +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time2 + Ll:time2 + Pl:time3 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_lses10_DEU$coefficients)[names(CLC_lses10_DEU$coefficients)=="time2:Ll"]="Ll:time2"
```

```
## Error: object 'CLC_lses10_DEU' not found
```

``` r
names(CLC_lses10_DEU$coefficients)[names(CLC_lses10_DEU$coefficients)=="time2:Ll:DL"]="Ll:time2:DL"
```

```
## Error: object 'CLC_lses10_DEU' not found
```

``` r
##Table 7##
#hypothesis testing:
stargazer(CLC_lses10_DEU,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
#drop others (DL==0):
ZtestfunT12(CLC_lses10_DEU)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
ZtestfunT(CLC_lses10_DEU,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
ZtestfunT(CLC_lses10_DEU,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
ZtestfunT(CLC_lses10_DEU,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
ZtestfunT(CLC_lses10_DEU,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
#drop Germany (DL==1):
ZtestfunD12(CLC_lses10_DEU)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
ZtestfunD(CLC_lses10_DEU,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
ZtestfunD(CLC_lses10_DEU,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
ZtestfunD(CLC_lses10_DEU,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
ZtestfunD(CLC_lses10_DEU,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
#difference in drop between Germany and others (DL==1 vs DL==0):
ZtestfunTD12(CLC_lses10_DEU)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses10_DDEU.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.2001,0.64)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.2001)+0.2001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU,0,1)) +#(high)
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU,0,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU,0,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU,0,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU,0,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU,0,6)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU,0,1)) +#(low)
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU,0,2)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU,0,3)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU,0,4)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU,0,5)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU,0,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##THEORY 10Y SEGMENTS - GERMANY - ALTERNATIVE THRESHOLDS AND FULL REUSLTS TABLE:----

#Germany dummy:
de$DL[de$Ec %in% c("DEU")]=1#Germany
```

```
## Error in `*tmp*`$DL: object of type 'closure' is not subsettable
```

``` r
de$DL[!de$Ec %in% c("DEU")]=0#others
```

```
## Error in `*tmp*`$DL: object of type 'closure' is not subsettable
```

``` r
#confidence interval functions:
CI.PlLllses10CGfun=function(CLC,t0,pe){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=8)#Pl:
  for (t in 1:59) {
    t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    #left:
    CI.PlLl[t,1]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6+
      CLC$coefficients["Pl:time2:DL"]*t2+CLC$coefficients["Pl:time3:DL"]*t3+CLC$coefficients["Pl:time4:DL"]*t4+CLC$coefficients["Pl:time5:DL"]*t5+CLC$coefficients["Pl:time6:DL"]*t6-
      (CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6+
         CLC$coefficients["Ll:time2:DL"]*t2+CLC$coefficients["Ll:time3:DL"]*t3+CLC$coefficients["Ll:time4:DL"]*t4+CLC$coefficients["Ll:time5:DL"]*t5+CLC$coefficients["Ll:time6:DL"]*t6)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      t2^2*vcov(CLC)["Pl:time2:DL","Pl:time2:DL"]+t3^2*vcov(CLC)["Pl:time3:DL","Pl:time3:DL"]+t4^2*vcov(CLC)["Pl:time4:DL","Pl:time4:DL"]+t5^2*vcov(CLC)["Pl:time5:DL","Pl:time5:DL"]+t6^2*vcov(CLC)["Pl:time6:DL","Pl:time6:DL"]+
      1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]+
      t2^2*vcov(CLC)["Ll:time2:DL","Ll:time2:DL"]+t3^2*vcov(CLC)["Ll:time3:DL","Ll:time3:DL"]+t4^2*vcov(CLC)["Ll:time4:DL","Ll:time4:DL"]+t5^2*vcov(CLC)["Ll:time5:DL","Ll:time5:DL"]+t6^2*vcov(CLC)["Ll:time6:DL","Ll:time6:DL"]-
      2*1*1*vcov(CLC)["Pl_ISL","Ll_ISL"]+2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6"]+
      2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2:DL"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2:DL"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3:DL"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3:DL"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4:DL"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4:DL"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5:DL"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5:DL"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6:DL"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6:DL"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2:DL"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2:DL"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3:DL"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3:DL"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4:DL"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4:DL"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5:DL"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5:DL"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6:DL"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6:DL"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6"]+
      2*t2*t2*vcov(CLC)["Pl:time2","Pl:time2:DL"]-2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2:DL"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3:DL"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3:DL"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4:DL"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4:DL"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5:DL"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5:DL"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6:DL"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6:DL"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]-
      2*t2*t2*vcov(CLC)["Ll:time2","Pl:time2:DL"]+2*t2*t2*vcov(CLC)["Ll:time2","Ll:time2:DL"]-2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3:DL"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3:DL"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4:DL"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4:DL"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5:DL"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5:DL"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6:DL"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]+
      2*t3*t2*vcov(CLC)["Pl:time3","Pl:time2:DL"]-2*t3*t2*vcov(CLC)["Pl:time3","Ll:time2:DL"]+2*t3*t3*vcov(CLC)["Pl:time3","Pl:time3:DL"]-2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t3*t2*vcov(CLC)["Ll:time3","Pl:time2:DL"]+2*t3*t2*vcov(CLC)["Ll:time3","Ll:time2:DL"]-2*t3*t3*vcov(CLC)["Ll:time3","Pl:time3:DL"]+2*t3*t3*vcov(CLC)["Ll:time3","Ll:time3:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]+
      2*t4*t2*vcov(CLC)["Pl:time4","Pl:time2:DL"]-2*t4*t2*vcov(CLC)["Pl:time4","Ll:time2:DL"]+2*t4*t3*vcov(CLC)["Pl:time4","Pl:time3:DL"]-2*t4*t3*vcov(CLC)["Pl:time4","Ll:time3:DL"]+
      2*t4*t4*vcov(CLC)["Pl:time4","Pl:time4:DL"]-2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t4*t2*vcov(CLC)["Ll:time4","Pl:time2:DL"]+2*t4*t2*vcov(CLC)["Ll:time4","Ll:time2:DL"]-2*t4*t3*vcov(CLC)["Ll:time4","Pl:time3:DL"]+2*t4*t3*vcov(CLC)["Ll:time4","Ll:time3:DL"]-
      2*t4*t4*vcov(CLC)["Ll:time4","Pl:time4:DL"]+2*t4*t4*vcov(CLC)["Ll:time4","Ll:time4:DL"]-2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]+
      2*t5*t2*vcov(CLC)["Pl:time5","Pl:time2:DL"]-2*t5*t2*vcov(CLC)["Pl:time5","Ll:time2:DL"]+2*t5*t3*vcov(CLC)["Pl:time5","Pl:time3:DL"]-2*t5*t3*vcov(CLC)["Pl:time5","Ll:time3:DL"]+
      2*t5*t4*vcov(CLC)["Pl:time5","Pl:time4:DL"]-2*t5*t4*vcov(CLC)["Pl:time5","Ll:time4:DL"]+2*t5*t5*vcov(CLC)["Pl:time5","Pl:time5:DL"]-2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t5*t2*vcov(CLC)["Ll:time5","Pl:time2:DL"]+2*t5*t2*vcov(CLC)["Ll:time5","Ll:time2:DL"]-2*t5*t3*vcov(CLC)["Ll:time5","Pl:time3:DL"]+2*t5*t3*vcov(CLC)["Ll:time5","Ll:time3:DL"]-
      2*t5*t4*vcov(CLC)["Ll:time5","Pl:time4:DL"]+2*t5*t4*vcov(CLC)["Ll:time5","Ll:time4:DL"]-2*t5*t5*vcov(CLC)["Ll:time5","Pl:time5:DL"]+2*t5*t5*vcov(CLC)["Ll:time5","Ll:time5:DL"]-2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]+
      2*t6*t2*vcov(CLC)["Pl:time6","Pl:time2:DL"]-2*t6*t2*vcov(CLC)["Pl:time6","Ll:time2:DL"]+2*t6*t3*vcov(CLC)["Pl:time6","Pl:time3:DL"]-2*t6*t3*vcov(CLC)["Pl:time6","Ll:time3:DL"]+
      2*t6*t4*vcov(CLC)["Pl:time6","Pl:time4:DL"]-2*t6*t4*vcov(CLC)["Pl:time6","Ll:time4:DL"]+2*t6*t5*vcov(CLC)["Pl:time6","Pl:time5:DL"]-2*t6*t5*vcov(CLC)["Pl:time6","Ll:time5:DL"]+2*t6*t6*vcov(CLC)["Pl:time6","Pl:time6:DL"]-2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6:DL"]-
      2*t6*t2*vcov(CLC)["Ll:time6","Pl:time2:DL"]+2*t6*t2*vcov(CLC)["Ll:time6","Ll:time2:DL"]-2*t6*t3*vcov(CLC)["Ll:time6","Pl:time3:DL"]+2*t6*t3*vcov(CLC)["Ll:time6","Ll:time3:DL"]-
      2*t6*t4*vcov(CLC)["Ll:time6","Pl:time4:DL"]+2*t6*t4*vcov(CLC)["Ll:time6","Ll:time4:DL"]-2*t6*t5*vcov(CLC)["Ll:time6","Pl:time5:DL"]+2*t6*t5*vcov(CLC)["Ll:time6","Ll:time5:DL"]-2*t6*t6*vcov(CLC)["Ll:time6","Pl:time6:DL"]+2*t6*t6*vcov(CLC)["Ll:time6","Ll:time6:DL"]-
      2*t2*t2*vcov(CLC)["Pl:time2:DL","Ll:time2:DL"]+2*t2*t3*vcov(CLC)["Pl:time2:DL","Pl:time3:DL"]-2*t2*t3*vcov(CLC)["Pl:time2:DL","Ll:time3:DL"]+
      2*t2*t4*vcov(CLC)["Pl:time2:DL","Pl:time4:DL"]-2*t2*t4*vcov(CLC)["Pl:time2:DL","Ll:time4:DL"]+2*t2*t5*vcov(CLC)["Pl:time2:DL","Pl:time5:DL"]-2*t2*t5*vcov(CLC)["Pl:time2:DL","Ll:time5:DL"]+2*t2*t6*vcov(CLC)["Pl:time2:DL","Pl:time6:DL"]-2*t2*t6*vcov(CLC)["Pl:time2:DL","Ll:time6:DL"]-
      2*t2*t3*vcov(CLC)["Ll:time2:DL","Pl:time3:DL"]+2*t2*t3*vcov(CLC)["Ll:time2:DL","Ll:time3:DL"]-
      2*t2*t4*vcov(CLC)["Ll:time2:DL","Pl:time4:DL"]+2*t2*t4*vcov(CLC)["Ll:time2:DL","Ll:time4:DL"]-2*t2*t5*vcov(CLC)["Ll:time2:DL","Pl:time5:DL"]+2*t2*t5*vcov(CLC)["Ll:time2:DL","Ll:time5:DL"]-2*t2*t6*vcov(CLC)["Ll:time2:DL","Pl:time6:DL"]+2*t2*t6*vcov(CLC)["Ll:time2:DL","Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3:DL","Ll:time3:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3:DL","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3:DL","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3:DL","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3:DL","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3:DL","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3:DL","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3:DL","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["Ll:time3:DL","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["Ll:time3:DL","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["Ll:time3:DL","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["Ll:time3:DL","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["Ll:time3:DL","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4:DL","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4:DL","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4:DL","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4:DL","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4:DL","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4:DL","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4:DL","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4:DL","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4:DL","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5:DL","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5:DL","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5:DL","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5:DL","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5:DL","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6:DL","Ll:time6:DL"]
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
    #right:
    CI.PlLl[t,5]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6-
      (CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6)#fitted values
    CI.PlLl[t,6]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]-
      2*1*1*vcov(CLC)["Pl_ISL","Ll_ISL"]+2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]
    CI.PlLl[t,7]=CI.PlLl[t,5]-qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI lower
    CI.PlLl[t,8]=CI.PlLl[t,5]+qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  if (pe==1) {CI.PlLl=CI.PlLl[1:(10+t0),]}
  if (pe==2) {CI.PlLl=CI.PlLl[(11+t0):(20+t0),]}
  if (pe==3) {CI.PlLl=CI.PlLl[(21+t0):(30+t0),]}
  if (pe==4) {CI.PlLl=CI.PlLl[(31+t0):(40+t0),]}
  if (pe==5) {CI.PlLl=CI.PlLl[(41+t0):(50+t0),]}
  if (pe==6) {CI.PlLl=CI.PlLl[(51+t0):59,]}
  CI.PlLl
}#wo Pl:time1:DL,Ll:time1:DL
CI.PlLllses10CGfun2=function(CLC,t0,pe){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=8)#Pl:
  for (t in 1:59) {
    t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    #left:
    CI.PlLl[t,1]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6+
      CLC$coefficients["Pl:time3:DL"]*t3+CLC$coefficients["Pl:time4:DL"]*t4+CLC$coefficients["Pl:time5:DL"]*t5+CLC$coefficients["Pl:time6:DL"]*t6-
      (CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6+
         CLC$coefficients["Ll:time3:DL"]*t3+CLC$coefficients["Ll:time4:DL"]*t4+CLC$coefficients["Ll:time5:DL"]*t5+CLC$coefficients["Ll:time6:DL"]*t6)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      t3^2*vcov(CLC)["Pl:time3:DL","Pl:time3:DL"]+t4^2*vcov(CLC)["Pl:time4:DL","Pl:time4:DL"]+t5^2*vcov(CLC)["Pl:time5:DL","Pl:time5:DL"]+t6^2*vcov(CLC)["Pl:time6:DL","Pl:time6:DL"]+
      1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]+
      t3^2*vcov(CLC)["Ll:time3:DL","Ll:time3:DL"]+t4^2*vcov(CLC)["Ll:time4:DL","Ll:time4:DL"]+t5^2*vcov(CLC)["Ll:time5:DL","Ll:time5:DL"]+t6^2*vcov(CLC)["Ll:time6:DL","Ll:time6:DL"]-
      2*1*1*vcov(CLC)["Pl_ISL","Ll_ISL"]+2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6"]+
      2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3:DL"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3:DL"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4:DL"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4:DL"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5:DL"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5:DL"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6:DL"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6:DL"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]-
      2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3:DL"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3:DL"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4:DL"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4:DL"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5:DL"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5:DL"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6:DL"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6:DL"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6"]+
      2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3:DL"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3:DL"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4:DL"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4:DL"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5:DL"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5:DL"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6:DL"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6:DL"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3:DL"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3:DL"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4:DL"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4:DL"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5:DL"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5:DL"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6:DL"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]+
      2*t3*t3*vcov(CLC)["Pl:time3","Pl:time3:DL"]-2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t3*t3*vcov(CLC)["Ll:time3","Pl:time3:DL"]+2*t3*t3*vcov(CLC)["Ll:time3","Ll:time3:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]+
      2*t4*t3*vcov(CLC)["Pl:time4","Pl:time3:DL"]-2*t4*t3*vcov(CLC)["Pl:time4","Ll:time3:DL"]+
      2*t4*t4*vcov(CLC)["Pl:time4","Pl:time4:DL"]-2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t4*t3*vcov(CLC)["Ll:time4","Pl:time3:DL"]+2*t4*t3*vcov(CLC)["Ll:time4","Ll:time3:DL"]-
      2*t4*t4*vcov(CLC)["Ll:time4","Pl:time4:DL"]+2*t4*t4*vcov(CLC)["Ll:time4","Ll:time4:DL"]-2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]+
      2*t5*t3*vcov(CLC)["Pl:time5","Pl:time3:DL"]-2*t5*t3*vcov(CLC)["Pl:time5","Ll:time3:DL"]+
      2*t5*t4*vcov(CLC)["Pl:time5","Pl:time4:DL"]-2*t5*t4*vcov(CLC)["Pl:time5","Ll:time4:DL"]+2*t5*t5*vcov(CLC)["Pl:time5","Pl:time5:DL"]-2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t5*t3*vcov(CLC)["Ll:time5","Pl:time3:DL"]+2*t5*t3*vcov(CLC)["Ll:time5","Ll:time3:DL"]-
      2*t5*t4*vcov(CLC)["Ll:time5","Pl:time4:DL"]+2*t5*t4*vcov(CLC)["Ll:time5","Ll:time4:DL"]-2*t5*t5*vcov(CLC)["Ll:time5","Pl:time5:DL"]+2*t5*t5*vcov(CLC)["Ll:time5","Ll:time5:DL"]-2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]+
      2*t6*t3*vcov(CLC)["Pl:time6","Pl:time3:DL"]-2*t6*t3*vcov(CLC)["Pl:time6","Ll:time3:DL"]+
      2*t6*t4*vcov(CLC)["Pl:time6","Pl:time4:DL"]-2*t6*t4*vcov(CLC)["Pl:time6","Ll:time4:DL"]+2*t6*t5*vcov(CLC)["Pl:time6","Pl:time5:DL"]-2*t6*t5*vcov(CLC)["Pl:time6","Ll:time5:DL"]+2*t6*t6*vcov(CLC)["Pl:time6","Pl:time6:DL"]-2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6:DL"]-
      2*t6*t3*vcov(CLC)["Ll:time6","Pl:time3:DL"]+2*t6*t3*vcov(CLC)["Ll:time6","Ll:time3:DL"]-
      2*t6*t4*vcov(CLC)["Ll:time6","Pl:time4:DL"]+2*t6*t4*vcov(CLC)["Ll:time6","Ll:time4:DL"]-2*t6*t5*vcov(CLC)["Ll:time6","Pl:time5:DL"]+2*t6*t5*vcov(CLC)["Ll:time6","Ll:time5:DL"]-2*t6*t6*vcov(CLC)["Ll:time6","Pl:time6:DL"]+2*t6*t6*vcov(CLC)["Ll:time6","Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3:DL","Ll:time3:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3:DL","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3:DL","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3:DL","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3:DL","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3:DL","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3:DL","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3:DL","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["Ll:time3:DL","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["Ll:time3:DL","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["Ll:time3:DL","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["Ll:time3:DL","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["Ll:time3:DL","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4:DL","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4:DL","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4:DL","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4:DL","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4:DL","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4:DL","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4:DL","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4:DL","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4:DL","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5:DL","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5:DL","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5:DL","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5:DL","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5:DL","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6:DL","Ll:time6:DL"]
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
    #right:
    CI.PlLl[t,5]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6-
      (CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6)#fitted values
    CI.PlLl[t,6]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]-
      2*1*1*vcov(CLC)["Pl_ISL","Ll_ISL"]+2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]
    CI.PlLl[t,7]=CI.PlLl[t,5]-qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI lower
    CI.PlLl[t,8]=CI.PlLl[t,5]+qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  if (pe==1) {CI.PlLl=CI.PlLl[1:(10+t0),]}
  if (pe==2) {CI.PlLl=CI.PlLl[(11+t0):(20+t0),]}
  if (pe==3) {CI.PlLl=CI.PlLl[(21+t0):(30+t0),]}
  if (pe==4) {CI.PlLl=CI.PlLl[(31+t0):(40+t0),]}
  if (pe==5) {CI.PlLl=CI.PlLl[(41+t0):(50+t0),]}
  if (pe==6) {CI.PlLl=CI.PlLl[(51+t0):59,]}
  CI.PlLl
}#wo Pl:time1:DL,Ll:time1:DL,Pl:time2:DL,Ll:time2:DL

#Z-test functions:
ZtestfunT12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2)]-CLC$coefficients[paste0("Ll:time",2)]#mean
  v=vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2)]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunTD12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2,":DL")]-CLC$coefficients[paste0("Ll:time",2,":DL")]#mean
  v=vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Pl:time",2,":DL")]+vcov(CLC)[paste0("Ll:time",2,":DL"),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Ll:time",2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunD12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2)]-CLC$coefficients[paste0("Ll:time",2)]+
    CLC$coefficients[paste0("Pl:time",2,":DL")]-CLC$coefficients[paste0("Ll:time",2,":DL")]#mean
  v=vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2)]+
    vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Pl:time",2,":DL")]+vcov(CLC)[paste0("Ll:time",2,":DL"),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2)]+2*vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",2),paste0("Pl:time",2,":DL")]+2*vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Ll:time",2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunT=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunTD=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1,":DL")]-CLC$coefficients[paste0("Ll:time",per1,":DL")]-
        CLC$coefficients[paste0("Pl:time",per2,":DL")]+CLC$coefficients[paste0("Ll:time",per2,":DL")])#mean
  v=vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per1,":DL")]+vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per1,":DL")]+
    vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Pl:time",per2,":DL")]+vcov(CLC)[paste0("Ll:time",per2,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2,":DL")]-2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Ll:time",per2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunD=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]+
        CLC$coefficients[paste0("Pl:time",per1,":DL")]-CLC$coefficients[paste0("Ll:time",per1,":DL")]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)]-
        CLC$coefficients[paste0("Pl:time",per2,":DL")]+CLC$coefficients[paste0("Ll:time",per2,":DL")])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per1,":DL")]+vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per1,":DL")]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]+
    vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Pl:time",per2,":DL")]+vcov(CLC)[paste0("Ll:time",per2,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]+2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per1,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1,":DL")]+2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2)]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2)]-
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per2),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Ll:time",per2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}


##Table D10##
##starting value for thresholds -4
#time variables:
t0=-4#starting value for thresholds (-4,-2,0,2,4)
de$time1=ifelse(de$time<=10+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regression:
CLC_lses10_DEU_m4=clogit(Va ~ Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                        Pl:time3:DL+Ll:time3:DL+Pl:time4:DL+Ll:time4:DL+Pl:time5:DL+Ll:time5:DL+Pl:time6:DL+Ll:time6:DL+
                        +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                      +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time2 + Ll:time2 + Pl:time3 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_lses10_DEU_m4$coefficients)[names(CLC_lses10_DEU_m4$coefficients)=="time2:Ll"]="Ll:time2"
```

```
## Error: object 'CLC_lses10_DEU_m4' not found
```

``` r
names(CLC_lses10_DEU_m4$coefficients)[names(CLC_lses10_DEU_m4$coefficients)=="time2:Ll:DL"]="Ll:time2:DL"
```

```
## Error: object 'CLC_lses10_DEU_m4' not found
```

``` r
#hypothesis testing:
stargazer(CLC_lses10_DEU_m4,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m4' not found
```

``` r
#drop others (DL==0):
ZtestfunT12(CLC_lses10_DEU_m4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m4' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_m4,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m4' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_m4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m4' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_m4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m4' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_m4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m4' not found
```

``` r
#drop Germany (DL==1):
# ZtestfunD12(CLC_lses10_DEU_m4)
# ZtestfunD(CLC_lses10_DEU_m4,2,3)
ZtestfunD(CLC_lses10_DEU_m4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m4' not found
```

``` r
ZtestfunD(CLC_lses10_DEU_m4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m4' not found
```

``` r
ZtestfunD(CLC_lses10_DEU_m4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m4' not found
```

``` r
#difference in drop between Germany and others (DL==1 vs DL==0):
# ZtestfunTD12(CLC_lses10_DEU_m4)
# ZtestfunTD(CLC_lses10_DEU_m4,2,3)
ZtestfunTD(CLC_lses10_DEU_m4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m4' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU_m4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m4' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU_m4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m4' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses10_DEU_m4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.2001,0.64)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.2001)+0.2001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun2(CLC_lses10_DEU_m4,-4,1)) +#(high)
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun2(CLC_lses10_DEU_m4,-4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun2(CLC_lses10_DEU_m4,-4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun2(CLC_lses10_DEU_m4,-4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun2(CLC_lses10_DEU_m4,-4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun2(CLC_lses10_DEU_m4,-4,6)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun2(CLC_lses10_DEU_m4,-4,1)) +#(low)
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun2(CLC_lses10_DEU_m4,-4,2)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun2(CLC_lses10_DEU_m4,-4,3)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun2(CLC_lses10_DEU_m4,-4,4)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun2(CLC_lses10_DEU_m4,-4,5)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun2(CLC_lses10_DEU_m4,-4,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##starting value for thresholds -2
#time variables:
t0=-2#starting value for thresholds (-4,-2,0,2,4)
de$time1=ifelse(de$time<=10+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regression:
CLC_lses10_DEU_m2=clogit(Va ~ Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                           Pl:time2:DL+Ll:time2:DL+Pl:time3:DL+Ll:time3:DL+Pl:time4:DL+Ll:time4:DL+Pl:time5:DL+Ll:time5:DL+Pl:time6:DL+Ll:time6:DL+
                           +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                         +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time2 + Ll:time2 + Pl:time3 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_lses10_DEU_m2$coefficients)[names(CLC_lses10_DEU_m2$coefficients)=="time2:Ll"]="Ll:time2"
```

```
## Error: object 'CLC_lses10_DEU_m2' not found
```

``` r
names(CLC_lses10_DEU_m2$coefficients)[names(CLC_lses10_DEU_m2$coefficients)=="time2:Ll:DL"]="Ll:time2:DL"
```

```
## Error: object 'CLC_lses10_DEU_m2' not found
```

``` r
#hypothesis testing:
stargazer(CLC_lses10_DEU_m2,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
#drop others (DL==0):
ZtestfunT12(CLC_lses10_DEU_m2)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_m2,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_m2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_m2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_m2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
#drop Germany (DL==1):
ZtestfunD12(CLC_lses10_DEU_m2)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
ZtestfunD(CLC_lses10_DEU_m2,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
ZtestfunD(CLC_lses10_DEU_m2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
ZtestfunD(CLC_lses10_DEU_m2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
ZtestfunD(CLC_lses10_DEU_m2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
#difference in drop between Germany and others (DL==1 vs DL==0):
ZtestfunTD12(CLC_lses10_DEU_m2)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU_m2,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU_m2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU_m2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU_m2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses10_DEU_m2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.2001,0.64)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.2001)+0.2001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_m2,-2,1)) +#(high)
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_m2,-2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_m2,-2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_m2,-2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_m2,-2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_m2,-2,6)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_m2,-2,1)) +#(low)
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_m2,-2,2)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_m2,-2,3)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_m2,-2,4)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_m2,-2,5)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_m2,-2,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##starting value for thresholds 2
#time variables:
t0=2#starting value for thresholds (-4,-2,0,2,4)
de$time1=ifelse(de$time<=10+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regression:
CLC_lses10_DEU_2=clogit(Va ~ Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                           Pl:time2:DL+Ll:time2:DL+Pl:time3:DL+Ll:time3:DL+Pl:time4:DL+Ll:time4:DL+Pl:time5:DL+Ll:time5:DL+Pl:time6:DL+Ll:time6:DL+
                           +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                         +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time2 + Ll:time2 + Pl:time3 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_lses10_DEU_2$coefficients)[names(CLC_lses10_DEU_2$coefficients)=="time2:Ll"]="Ll:time2"
```

```
## Error: object 'CLC_lses10_DEU_2' not found
```

``` r
names(CLC_lses10_DEU_2$coefficients)[names(CLC_lses10_DEU_2$coefficients)=="time2:Ll:DL"]="Ll:time2:DL"
```

```
## Error: object 'CLC_lses10_DEU_2' not found
```

``` r
#hypothesis testing:
stargazer(CLC_lses10_DEU_2,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
#drop others (DL==0):
ZtestfunT12(CLC_lses10_DEU_2)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_2,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
#drop Germany (DL==1):
ZtestfunD12(CLC_lses10_DEU_2)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
ZtestfunD(CLC_lses10_DEU_2,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
ZtestfunD(CLC_lses10_DEU_2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
ZtestfunD(CLC_lses10_DEU_2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
ZtestfunD(CLC_lses10_DEU_2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
#difference in drop between Germany and others (DL==1 vs DL==0):
ZtestfunTD12(CLC_lses10_DEU_2)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU_2,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU_2,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU_2,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU_2,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses10_DEU_2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.2001,0.64)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.2001)+0.2001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_2,2,1)) +#(high)
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_2,2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_2,2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_2,2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_2,2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_2,2,6)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_2,2,1)) +#(low)
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_2,2,2)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_2,2,3)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_2,2,4)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_2,2,5)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_2,2,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##starting value for thresholds 4
#time variables:
t0=4#starting value for thresholds (-4,-2,0,2,4)
de$time1=ifelse(de$time<=10+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regression:
CLC_lses10_DEU_4=clogit(Va ~ Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                          Pl:time2:DL+Ll:time2:DL+Pl:time3:DL+Ll:time3:DL+Pl:time4:DL+Ll:time4:DL+Pl:time5:DL+Ll:time5:DL+Pl:time6:DL+Ll:time6:DL+
                          +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                        +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time2 + Ll:time2 + Pl:time3 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_lses10_DEU_4$coefficients)[names(CLC_lses10_DEU_4$coefficients)=="time2:Ll"]="Ll:time2"
```

```
## Error: object 'CLC_lses10_DEU_4' not found
```

``` r
names(CLC_lses10_DEU_4$coefficients)[names(CLC_lses10_DEU_4$coefficients)=="time2:Ll:DL"]="Ll:time2:DL"
```

```
## Error: object 'CLC_lses10_DEU_4' not found
```

``` r
#hypothesis testing:
stargazer(CLC_lses10_DEU_4,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
#drop others (DL==0):
ZtestfunT12(CLC_lses10_DEU_4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_4,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
ZtestfunT(CLC_lses10_DEU_4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
#drop Germany (DL==1):
ZtestfunD12(CLC_lses10_DEU_4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
ZtestfunD(CLC_lses10_DEU_4,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
ZtestfunD(CLC_lses10_DEU_4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
ZtestfunD(CLC_lses10_DEU_4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
ZtestfunD(CLC_lses10_DEU_4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
#difference in drop between Germany and others (DL==1 vs DL==0):
ZtestfunTD12(CLC_lses10_DEU_4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU_4,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU_4,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU_4,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
ZtestfunTD(CLC_lses10_DEU_4,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses10_DEU_4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.2001,0.64)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.2001)+0.2001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_4,4,1)) +#(high)
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_4,4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_4,4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_4,4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_4,4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses10_DEU_4,4,6)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_4,4,1)) +#(low)
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_4,4,2)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_4,4,3)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_4,4,4)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_4,4,5)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses10_DEU_4,4,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##Table I8##
##table full results:
cm4=CLC_lses10_DEU_m4#shorten name for stargazer:
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m4' not found
```

``` r
cm2=CLC_lses10_DEU_m2
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_m2' not found
```

``` r
c0=CLC_lses10_DEU
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU' not found
```

``` r
c2=CLC_lses10_DEU_2
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_2' not found
```

``` r
c4=CLC_lses10_DEU_4
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses10_DEU_4' not found
```

``` r
stargazer(cm4,cm2,c0,c2,c4)#table
```

```
## Error in eval(expr, envir, enclos): object 'cm4' not found
```

``` r
rm(cm4,cm2,c0,c2,c4)


#THEORY CMP CATEGORIES:----

#prepare data:
dc=read.xlsx("MPDataset_MPDS2020b.xlsx")#read CMP project data
dc$pertot=rowSums(dc[,26:81],na.rm=T)#total per coded
dc$perrile=rowSums(dc[,names(dc) %in% c("per104","per201","per203","per305","per401","per402","per407","per414","per505",
                                        "per601","per603","per605","per606","per103","per105","per106","per107","per403",
                                        "per404","per406","per412","per413","per504","per506","per701","per202")],na.rm=T)#total abs per rile
dc$sharerile=dc$perrile/dc$pertot#share per rile/tot per
dc$Ey=as.numeric(substr(as.numeric(dc$date),1,4))#code year
dc=dc[dc$Ey>1960,]#keep only years in de dataset
dc=dc[dc$countryname %in% c("Australia","Austria","Canada","Denmark","Finland","Germany","United Kingdom","Greece","Iceland","Ireland"
                            ,"Israel","Italy","Netherlands","New Zealand","Norway","Portugal","Spain","Sweden"),]#keep only countries in de
colnames(dc)[colnames(dc)=="countryname"]="Ec"
temp=c("AUS","AUT","CAN","DNK","FIN","DEU","GBR","GRC","ISL","IRL"#assign same names Ec in de
       ,"ISR","ITA","NLD","NZL","NOR","PRT","ESP","SWE")#new cty names
names(temp)=c("Australia","Austria","Canada","Denmark","Finland","Germany","United Kingdom","Greece","Iceland","Ireland"
              ,"Israel","Italy","Netherlands","New Zealand","Norway","Portugal","Spain","Sweden")#old cty names
dc$Ec[dc$Ec %in% names(temp)]=temp[dc$Ec[dc$Ec %in% names(temp)]]#assign new cty names

# dc=dc %>% group_by(Ec,Ey) %>% mutate(sharerile_cy=weightedMean(sharerile,w=pervote,na.rm=TRUE))#avg share rile by Ec,Ey
dc=dc %>% group_by(Ec,Ey) %>% mutate(sharerile_cy=mean(sharerile,na.rm=TRUE))#avg share rile by Ec,Ey
dc=dc %>% group_by(Ec,Ey) %>% filter(row_number()==1)#keep only 1 Ec for Ey
dc$i=c(1:nrow(dc))#create index for robust lm estimation
dc$time=dc$Ey-1960#time
# dc=merge(ds,dc,by=c("Ec","Ey"),all.x=T,all.y=F)#to limit to ds (and de) observations/elections
dc$sharerile_cy=dc$sharerile_cy*100#use % instead than share

#CI function:
CI.LM_dc=function(LM,t0,pe){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=4)#Pl:
  for (t in 1:59) {
    # t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.PlLl[t,1]=LM$coefficients[paste0("(Intercept)")]+LM$coefficients["time2"]*t2+LM$coefficients["time3"]*t3+LM$coefficients["time4"]*t4+LM$coefficients["time5"]*t5+LM$coefficients["time6"]*t6#fitted values
    CI.PlLl[t,2]=1*vcov(LM)[paste0("(Intercept)"),paste0("(Intercept)")]+t2^2*vcov(LM)["time2","time2"]+t3^2*vcov(LM)["time3","time3"]+t4^2*vcov(LM)["time4","time4"]+t5^2*vcov(LM)["time5","time5"]+t6^2*vcov(LM)["time6","time6"]+
      2*1*t2*vcov(LM)[paste0("(Intercept)"),"time2"]+2*1*t3*vcov(LM)[paste0("(Intercept)"),"time3"]+2*1*t4*vcov(LM)[paste0("(Intercept)"),"time4"]+2*1*t5*vcov(LM)[paste0("(Intercept)"),"time5"]+2*1*t6*vcov(LM)[paste0("(Intercept)"),"time6"]+
      2*t2*t3*vcov(LM)["time2","time3"]+2*t2*t4*vcov(LM)["time2","time4"]+2*t2*t5*vcov(LM)["time2","time5"]+2*t2*t6*vcov(LM)["time2","time6"]+
      2*t3*t4*vcov(LM)["time3","time4"]+2*t3*t5*vcov(LM)["time3","time5"]+2*t3*t6*vcov(LM)["time3","time6"]+
      2*t4*t5*vcov(LM)["time4","time5"]+2*t4*t6*vcov(LM)["time4","time6"]+
      2*t5*t6*vcov(LM)["time5","time6"]#Variance
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  if (pe==1) {CI.PlLl=CI.PlLl[1:(10+t0),]}
  if (pe==2) {CI.PlLl=CI.PlLl[(11+t0):(20+t0),]}
  if (pe==3) {CI.PlLl=CI.PlLl[(21+t0):(30+t0),]}
  if (pe==4) {CI.PlLl=CI.PlLl[(31+t0):(40+t0),]}
  if (pe==5) {CI.PlLl=CI.PlLl[(41+t0):(50+t0),]}
  if (pe==6) {CI.PlLl=CI.PlLl[(51+t0):59,]}
  CI.PlLl
}#w/constant
CI.LM_dc=function(LM,t0,pe){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=4)#Pl:
  for (t in 1:59) {
    # t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.PlLl[t,1]=LM$coefficients[paste0("factor(Ec)ISL")]+LM$coefficients["time2"]*t2+LM$coefficients["time3"]*t3+LM$coefficients["time4"]*t4+LM$coefficients["time5"]*t5+LM$coefficients["time6"]*t6#fitted values
    CI.PlLl[t,2]=1*vcov(LM)[paste0("factor(Ec)ISL"),paste0("factor(Ec)ISL")]+t2^2*vcov(LM)["time2","time2"]+t3^2*vcov(LM)["time3","time3"]+t4^2*vcov(LM)["time4","time4"]+t5^2*vcov(LM)["time5","time5"]+t6^2*vcov(LM)["time6","time6"]+
      2*1*t2*vcov(LM)[paste0("factor(Ec)ISL"),"time2"]+2*1*t3*vcov(LM)[paste0("factor(Ec)ISL"),"time3"]+2*1*t4*vcov(LM)[paste0("factor(Ec)ISL"),"time4"]+2*1*t5*vcov(LM)[paste0("factor(Ec)ISL"),"time5"]+2*1*t6*vcov(LM)[paste0("factor(Ec)ISL"),"time6"]+
      2*t2*t3*vcov(LM)["time2","time3"]+2*t2*t4*vcov(LM)["time2","time4"]+2*t2*t5*vcov(LM)["time2","time5"]+2*t2*t6*vcov(LM)["time2","time6"]+
      2*t3*t4*vcov(LM)["time3","time4"]+2*t3*t5*vcov(LM)["time3","time5"]+2*t3*t6*vcov(LM)["time3","time6"]+
      2*t4*t5*vcov(LM)["time4","time5"]+2*t4*t6*vcov(LM)["time4","time6"]+
      2*t5*t6*vcov(LM)["time5","time6"]#Variance
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  if (pe==1) {CI.PlLl=CI.PlLl[1:(10+t0),]}
  if (pe==2) {CI.PlLl=CI.PlLl[(11+t0):(20+t0),]}
  if (pe==3) {CI.PlLl=CI.PlLl[(21+t0):(30+t0),]}
  if (pe==4) {CI.PlLl=CI.PlLl[(31+t0):(40+t0),]}
  if (pe==5) {CI.PlLl=CI.PlLl[(41+t0):(50+t0),]}
  if (pe==6) {CI.PlLl=CI.PlLl[(51+t0):59,]}
  CI.PlLl
}#w/cty FE

#Z-test functions:
Ztestfun=function(CLC,per1,per2){
  m=CLC$coefficients[paste0("time",per2)]-CLC$coefficients[paste0("time",per1)]#mean
  v=vcov(CLC)[paste0("time",per1),paste0("time",per1)]+vcov(CLC)[paste0("time",per2),paste0("time",per2)]-
    vcov(CLC)[paste0("time",per1),paste0("time",per2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}


##rile scale:
#create dataset density dydc_10:
dydc_10 = dc %>% group_by(Ey) %>% mutate(Eyn=n())#number of obs by Ey
dydc_10$Eyn=dydc_10$Eyn/nrow(dydc_10)#density by Ey
dydc_10=dydc_10 %>% group_by(Ey) %>% filter(row_number()==1)#keep only 1 obs per Ey
# dydc_10$Eyn=dydc_10$Eyn*50#density by Ey scaled up for graphs
# dydc_10$Eyn=dydc_10$Eyn+45#density by Ey shifted upward for graphs
#time variables:
t0=0#starting value for thresholds (-4,-2,0,2,4)
# dc$time1=ifelse(dc$time<=10+t0,1,0)
dc$time2=ifelse(dc$time>10+t0&dc$time<=20+t0,1,0)
dc$time3=ifelse(dc$time>20+t0&dc$time<=30+t0,1,0)
dc$time4=ifelse(dc$time>30+t0&dc$time<=40+t0,1,0)
dc$time5=ifelse(dc$time>40+t0&dc$time<=50+t0,1,0)
dc$time6=ifelse(dc$time>50+t0,1,0)
#regression:
L_dc_10=lm(sharerile_cy~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc)
LM_dc_10=lm_robust(sharerile_cy~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,cluster=i)


##Table 8## Left - Right
#plots (median cty):
# tikz(paste0("plot_","LM_dc_10.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Left$-$Right") +xlab("Year") +ylab("estimated share") + coord_cartesian(ylim=c(45.01,60)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(60-45.01)+45.01))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dydc_10) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10,0,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10,0,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10,0,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10,0,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10,0,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10,0,6)) )
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-1.png)

``` r
# dev.off()
#table (hypothesis testing):
LM_dc_10$r.squared
```

```
## [1] 0.9878034
```

``` r
LM_dc_10$nobs
```

```
## [1] 302
```

``` r
c(LM_dc_10$coefficients["time2"],LM_dc_10$std.error["time2"],LM_dc_10$p.value["time2"])#t2-t1=time2
```

```
##     time2     time2     time2 
## 0.4204245 1.3477887 0.7557923
```

``` r
Ztestfun(LM_dc_10,2,3)
```

```
##      time3                 time3 
## -2.9797883  1.5234167  0.0504663
```

``` r
Ztestfun(LM_dc_10,3,4)
```

```
##      time4                 time4 
## -0.4371503  1.6205592  0.7873505
```

``` r
Ztestfun(LM_dc_10,4,5)
```

```
##     time5               time5 
## 0.4677927 1.7038028 0.7836558
```

``` r
Ztestfun(LM_dc_10,5,6)
```

```
##     time6               time6 
## 0.7973152 1.6053872 0.6194361
```

``` r
##biggest increases and decreases in rile:
dctemp=dc[,names(dc) %in% c(paste0("per",101:706),"Ey")]
dctemp$y20[dctemp$Ey>=1960&dctemp$Ey<1980]=1
dctemp$y20[dctemp$Ey>=1980&dctemp$Ey<2000]=2
dctemp$y20[dctemp$Ey>=2000]=3
dctemp[nrow(dctemp)+1,]=t(colMeans(dctemp[dctemp$y20==1,],na.rm=T))
dctemp[nrow(dctemp)+1,]=t(colMeans(dctemp[dctemp$y20==2,],na.rm=T))
dctemp[nrow(dctemp)+1,]=t(colMeans(dctemp[dctemp$y20==3,],na.rm=T))
dctemp=dctemp[303:305,]
dctemp[nrow(dctemp)+1,]=dctemp[3,]-dctemp[1,]
dctemp=as.matrix(dctemp)
sort(dctemp[4,],decreasing=T)#biggest increases per501; per503
```

```
##            Ey        per501        per503        per416        per506           y20        per504        per201        per305        per605        per602        per502        per607        per304        per303        per108        per705        per604        per401        per110        per301        per415        per603        per608        per505        per606        per407        per601        per507        per409        per103        per411        per204        per107        per702        per405        per105        per109        per302        per414        per402        per203        per704        per403        per102        per406        per413        per104        per101        per701        per706        per410        per412        per408        per106        per703        per202        per404 
## 38.8702786378  9.4058034393  4.0983179781  3.6798821261  2.0942028140  2.0000000000  1.6672198020  1.4024145909  1.0416974466  0.9839188119  0.8593931214  0.8445159979  0.7896117770  0.7847031787  0.7517614382  0.6457960396  0.6070561751  0.4239885357  0.3644801459  0.3184772277  0.3028268890  0.2276822303  0.1458144867  0.0902242835  0.0621025534  0.0582461699  0.0316135487  0.0226759771  0.0146097968  0.0064128192  0.0024934862  0.0005377801 -0.0303655029 -0.0668679521 -0.1351298593 -0.2019377801 -0.2269528921 -0.2314125065 -0.3163976029 -0.3494018760 -0.3630611777 -0.4581073476 -0.5195297551 -0.5206128192 -0.5467815529 -0.5502569046 -0.6950076081 -0.7088706618 -1.0181931214 -1.1129716519 -1.1638267848 -1.2648775404 -1.3384783742 -1.3974760813 -1.5505294424 -1.7929864513 -2.2394699323 -2.2924171965
```

``` r
# sort(dctemp[4,])#biggest decreases per404; per202
rm(dctemp)

#create dataset density dydc_per:
dydc_per = dc %>% group_by(Ey) %>% mutate(Eyn=n())#number of obs by Ey
dydc_per$Eyn=dydc_per$Eyn/nrow(dydc_per)#density by Ey
dydc_per=dydc_per %>% group_by(Ey) %>% filter(row_number()==1)#keep only 1 obs per Ey
# dydc_per$Eyn=dydc_per$Eyn*20#density by Ey scaled down for graphs
# dydc_per$Eyn=dydc_per$Eyn+0#density by Ey shifted upward for graphs


##per501 Environmental Protection:
# General policies in favour of protecting the environment, fighting climate change,
#  and other “green” policies. For instance:
# • General preservation of natural resources; 
# • Preservation of countryside, forests, etc.; 
# • Protection of national parks;
# • Animal rights.
#regression:
L_dc_10_per501=lm(per501~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,weights=pervote)
LM_dc_10_per501=lm_robust(per501~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,cluster=i,weights=pervote)


##Table 8## Environmental Protection
#plots (median cty):
# tikz(paste0("plot_","LM_dc_10_per501.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Environmental Protection") +xlab("Year") +ylab("estimated share") + coord_cartesian(ylim=c(0.0001,15)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(15-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dydc_per) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_per501,0,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_per501,0,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_per501,0,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_per501,0,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_per501,0,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_per501,0,6)) )
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-2.png)

``` r
# dev.off()
#table (hypothesis testing):
LM_dc_10_per501$r.squared
```

```
## [1] 0.6551242
```

``` r
LM_dc_10_per501$nobs
```

```
## [1] 299
```

``` r
c(LM_dc_10_per501$coefficients["time2"],LM_dc_10_per501$std.error["time2"],LM_dc_10_per501$p.value["time2"])#t2-t1=time2
```

```
##     time2     time2     time2 
## 2.0908260 0.6797620 0.0039705
```

``` r
Ztestfun(LM_dc_10_per501,2,3)
```

```
##        time3                     time3 
## 3.3190304003 0.9768789056 0.0006798314
```

``` r
Ztestfun(LM_dc_10_per501,3,4)
```

```
##     time4               time4 
## 3.1312014 1.5521012 0.0436543
```

``` r
Ztestfun(LM_dc_10_per501,4,5)
```

```
##      time5                 time5 
## -0.1963935  1.8879802  0.9171511
```

``` r
Ztestfun(LM_dc_10_per501,5,6)
```

```
##     time6               time6 
## 1.0523127 1.6398854 0.5210687
```

``` r
##per503 Equality: Positive:
# Concept of social justice and the need for fair treatment of all people. This may include:
# • Special protection for underprivileged social groups;
# • Removal of class barriers;
# • Need for fair distribution of resources;
# • The end of discrimination (e.g. racial or sexual discrimination).
#regression:
L_dc_10_per503=lm(per503~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,weights=pervote)
LM_dc_10_per503=lm_robust(per503~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,cluster=i,weights=pervote)


##Table 8## Equality Positive
#plots (median cty):
# tikz(paste0("plot_","LM_dc_10_per503.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Equality, Positive") +xlab("Year") +ylab("estimated share") + coord_cartesian(ylim=c(0.0001,15)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(15-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dydc_per) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_per503,0,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_per503,0,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_per503,0,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_per503,0,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_per503,0,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_per503,0,6)) )
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-3.png)

``` r
# dev.off()
LM_dc_10_per503$r.squared
```

```
## [1] 0.7427401
```

``` r
LM_dc_10_per503$nobs
```

```
## [1] 299
```

``` r
c(LM_dc_10_per503$coefficients["time2"],LM_dc_10_per503$std.error["time2"],LM_dc_10_per503$p.value["time2"])#t2-t1=time2
```

```
##     time2     time2     time2 
## 0.9132563 0.8751060 0.3035549
```

``` r
Ztestfun(LM_dc_10_per503,2,3)
```

```
##     time3               time3 
## 1.1972116 1.0183283 0.2397293
```

``` r
Ztestfun(LM_dc_10_per503,3,4)
```

```
##     time4               time4 
## 1.9345893 1.4472852 0.1813199
```

``` r
Ztestfun(LM_dc_10_per503,4,5)
```

```
##     time5               time5 
## 0.3728527 1.6967905 0.8260737
```

``` r
Ztestfun(LM_dc_10_per503,5,6)
```

```
##    time6             time6 
## 0.542140 1.448789 0.708254
```

``` r
##THEORY CMP CATEGORIES - RILE - ALTERNATIVE THRESHOLDS:----

##Table D11##
##starting value for thresholds -4
#time variables:
t0=-4#starting value for thresholds (-4,-2,0,2,4)
# dc$time1=ifelse(dc$time<=10+t0,1,0)
dc$time2=ifelse(dc$time>10+t0&dc$time<=20+t0,1,0)
dc$time3=ifelse(dc$time>20+t0&dc$time<=30+t0,1,0)
dc$time4=ifelse(dc$time>30+t0&dc$time<=40+t0,1,0)
dc$time5=ifelse(dc$time>40+t0&dc$time<=50+t0,1,0)
dc$time6=ifelse(dc$time>50+t0,1,0)
#regression:
L_dc_10_m4=lm(sharerile_cy~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc)
LM_dc_10_m4=lm_robust(sharerile_cy~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,cluster=i)
#plots (median cty):
# tikz(paste0("plot_","LM_dc_10_m4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Left$-$Right") +xlab("Year") +ylab("estimated share") + coord_cartesian(ylim=c(45.01,60)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(60-45.01)+45.01))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dydc_10) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_m4,-4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_m4,-4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_m4,-4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_m4,-4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_m4,-4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_m4,-4,6)) )
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-4.png)

``` r
# dev.off()
#table (hypothesis testing):
LM_dc_10_m4$r.squared
```

```
## [1] 0.9879095
```

``` r
LM_dc_10_m4$nobs
```

```
## [1] 302
```

``` r
c(LM_dc_10_m4$coefficients["time2"],LM_dc_10_m4$std.error["time2"],LM_dc_10_m4$p.value["time2"])#t2-t1=time2
```

```
##     time2     time2     time2 
## 1.1484100 1.6280864 0.4834452
```

``` r
Ztestfun(LM_dc_10_m4,2,3)
```

```
##     time3               time3 
## -2.159052  1.829630  0.237981
```

``` r
Ztestfun(LM_dc_10_m4,3,4)
```

```
##      time4                 time4 
## -2.4159053  1.6935266  0.1537088
```

``` r
Ztestfun(LM_dc_10_m4,4,5)
```

```
##     time5               time5 
## 2.1168937 1.8412897 0.2502757
```

``` r
Ztestfun(LM_dc_10_m4,5,6)
```

```
##      time6                 time6 
## -0.8696438  1.8198203  0.6327403
```

``` r
##starting value for thresholds -2
#time variables:
t0=-2#starting value for thresholds (-4,-2,0,2,4)
# dc$time1=ifelse(dc$time<=10+t0,1,0)
dc$time2=ifelse(dc$time>10+t0&dc$time<=20+t0,1,0)
dc$time3=ifelse(dc$time>20+t0&dc$time<=30+t0,1,0)
dc$time4=ifelse(dc$time>30+t0&dc$time<=40+t0,1,0)
dc$time5=ifelse(dc$time>40+t0&dc$time<=50+t0,1,0)
dc$time6=ifelse(dc$time>50+t0,1,0)
#regression:
L_dc_10_m2=lm(sharerile_cy~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc)
LM_dc_10_m2=lm_robust(sharerile_cy~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,cluster=i)
#plots (median cty):
# tikz(paste0("plot_","LM_dc_10_m2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Left$-$Right") +xlab("Year") +ylab("estimated share") + coord_cartesian(ylim=c(45.01,60)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(60-45.01)+45.01))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dydc_10) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_m2,-2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_m2,-2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_m2,-2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_m2,-2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_m2,-2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_m2,-2,6)) )
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-5.png)

``` r
# dev.off()
#table (hypothesis testing):
LM_dc_10_m2$r.squared
```

```
## [1] 0.9878519
```

``` r
LM_dc_10_m2$nobs
```

```
## [1] 302
```

``` r
c(LM_dc_10_m2$coefficients["time2"],LM_dc_10_m2$std.error["time2"],LM_dc_10_m2$p.value["time2"])#t2-t1=time2
```

```
##     time2     time2     time2 
## 1.0187248 1.4726940 0.4913663
```

``` r
Ztestfun(LM_dc_10_m2,2,3)
```

```
##      time3                 time3 
## -2.2961980  1.6581164  0.1661065
```

``` r
Ztestfun(LM_dc_10_m2,3,4)
```

```
##      time4                 time4 
## -1.9540177  1.6157133  0.2265154
```

``` r
Ztestfun(LM_dc_10_m2,4,5)
```

```
##     time5               time5 
## 1.0971381 1.7633857 0.5338255
```

``` r
Ztestfun(LM_dc_10_m2,5,6)
```

```
##     time6               time6 
## 0.2219802 1.7164544 0.8971006
```

``` r
##starting value for thresholds 2
#time variables:
t0=2#starting value for thresholds (-4,-2,0,2,4)
# dc$time1=ifelse(dc$time<=10+t0,1,0)
dc$time2=ifelse(dc$time>10+t0&dc$time<=20+t0,1,0)
dc$time3=ifelse(dc$time>20+t0&dc$time<=30+t0,1,0)
dc$time4=ifelse(dc$time>30+t0&dc$time<=40+t0,1,0)
dc$time5=ifelse(dc$time>40+t0&dc$time<=50+t0,1,0)
dc$time6=ifelse(dc$time>50+t0,1,0)
#regression:
L_dc_10_2=lm(sharerile_cy~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc)
LM_dc_10_2=lm_robust(sharerile_cy~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,cluster=i)
#plots (median cty):
# tikz(paste0("plot_","LM_dc_10_2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Left$-$Right") +xlab("Year") +ylab("estimated share") + coord_cartesian(ylim=c(45.01,60)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(60-45.01)+45.01))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dydc_10) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_2,2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_2,2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_2,2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_2,2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_2,2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_2,2,6)) )
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-6.png)

``` r
# dev.off()
# table (hypothesis testing):
LM_dc_10_2$r.squared
```

```
## [1] 0.9878553
```

``` r
LM_dc_10_2$nobs
```

```
## [1] 302
```

``` r
c(LM_dc_10_2$coefficients["time2"],LM_dc_10_2$std.error["time2"],LM_dc_10_2$p.value["time2"])#t2-t1=time2
```

```
##     time2     time2     time2 
## 0.5895398 1.2822826 0.6466176
```

``` r
Ztestfun(LM_dc_10_2,2,3)
```

```
##        time3                     time3 
## -3.829894149  1.441154686  0.007871845
```

``` r
Ztestfun(LM_dc_10_2,3,4)
```

```
##     time4               time4 
## 1.1252953 1.5317539 0.4625557
```

``` r
Ztestfun(LM_dc_10_2,4,5)
```

```
##       time5                   time5 
## -0.08266603  1.64379766  0.95989156
```

``` r
Ztestfun(LM_dc_10_2,5,6)
```

```
##     time6               time6 
## 0.2432978 1.5857103 0.8780581
```

``` r
##starting value for thresholds 4
#time variables:
t0=4#starting value for thresholds (-4,-2,0,2,4)
# dc$time1=ifelse(dc$time<=10+t0,1,0)
dc$time2=ifelse(dc$time>10+t0&dc$time<=20+t0,1,0)
dc$time3=ifelse(dc$time>20+t0&dc$time<=30+t0,1,0)
dc$time4=ifelse(dc$time>30+t0&dc$time<=40+t0,1,0)
dc$time5=ifelse(dc$time>40+t0&dc$time<=50+t0,1,0)
dc$time6=ifelse(dc$time>50+t0,1,0)
#regression:
L_dc_10_4=lm(sharerile_cy~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc)
LM_dc_10_4=lm_robust(sharerile_cy~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,cluster=i)
#plots (median cty):
# tikz(paste0("plot_","LM_dc_10_4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Left$-$Right") +xlab("Year") +ylab("estimated share") + coord_cartesian(ylim=c(45.01,60)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(60-45.01)+45.01))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dydc_10) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_4,4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_4,4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_4,4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_4,4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_4,4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LM_dc_10_4,4,6)) )
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-7.png)

``` r
# dev.off()
# table (hypothesis testing):
LM_dc_10_4$r.squared
```

```
## [1] 0.9877525
```

``` r
LM_dc_10_4$nobs
```

```
## [1] 302
```

``` r
c(LM_dc_10_4$coefficients["time2"],LM_dc_10_4$std.error["time2"],LM_dc_10_4$p.value["time2"])#t2-t1=time2
```

```
##     time2     time2     time2 
## -1.125810  1.160461  0.333968
```

``` r
Ztestfun(LM_dc_10_4,2,3)
```

```
##       time3                   time3 
## -2.58882452  1.35456576  0.05598093
```

``` r
Ztestfun(LM_dc_10_4,3,4)
```

```
##     time4               time4 
## 1.2354889 1.5638336 0.4295052
```

``` r
Ztestfun(LM_dc_10_4,4,5)
```

```
##      time5                 time5 
## -0.1491898  1.6619551  0.9284719
```

``` r
Ztestfun(LM_dc_10_4,5,6)
```

```
##     time6               time6 
## 0.4409509 1.5494972 0.7759684
```

``` r
##Table I9##
##table full results:
stargazer(L_dc_10_m4,L_dc_10_m2,L_dc_10,L_dc_10_2,L_dc_10_4,
          se = list(LM_dc_10_m4$std.error,LM_dc_10_m2$std.error,LM_dc_10$std.error,LM_dc_10_2$std.error,LM_dc_10_4$std.error))
```

```
## 
## % Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
## % Date and time: Thu, Dec 04, 2025 - 11:03:51
## \begin{table}[!htbp] \centering 
##   \caption{} 
##   \label{} 
## \begin{tabular}{@{\extracolsep{5pt}}lccccc} 
## \\[-1.8ex]\hline 
## \hline \\[-1.8ex] 
##  & \multicolumn{5}{c}{\textit{Dependent variable:}} \\ 
## \cline{2-6} 
## \\[-1.8ex] & \multicolumn{5}{c}{sharerile\_cy} \\ 
## \\[-1.8ex] & (1) & (2) & (3) & (4) & (5)\\ 
## \hline \\[-1.8ex] 
##  time2 & 1.148 & 1.019 & 0.420 & 0.590 & $-$1.126 \\ 
##   & (1.628) & (1.473) & (1.348) & (1.282) & (1.160) \\ 
##   & & & & & \\ 
##  time3 & $-$1.011 & $-$1.277 & $-$2.559$^{**}$ & $-$3.240$^{***}$ & $-$3.715$^{***}$ \\ 
##   & (1.528) & (1.368) & (1.232) & (1.112) & (1.063) \\ 
##   & & & & & \\ 
##  time4 & $-$3.427$^{**}$ & $-$3.231$^{**}$ & $-$2.997$^{**}$ & $-$2.115 & $-$2.479$^{*}$ \\ 
##   & (1.468) & (1.432) & (1.455) & (1.371) & (1.396) \\ 
##   & & & & & \\ 
##  time5 & $-$1.310 & $-$2.134 & $-$2.529$^{*}$ & $-$2.198$^{*}$ & $-$2.628$^{**}$ \\ 
##   & (1.673) & (1.531) & (1.338) & (1.261) & (1.204) \\ 
##   & & & & & \\ 
##  time6 & $-$2.179 & $-$1.912 & $-$1.731 & $-$1.954 & $-$2.187$^{*}$ \\ 
##   & (1.450) & (1.377) & (1.338) & (1.311) & (1.267) \\ 
##   & & & & & \\ 
##  factor(Ec)AUS & 60.361$^{***}$ & 60.328$^{***}$ & 60.584$^{***}$ & 60.532$^{***}$ & 60.859$^{***}$ \\ 
##   & (2.064) & (2.070) & (1.984) & (1.858) & (1.809) \\ 
##   & & & & & \\ 
##  factor(Ec)AUT & 54.715$^{***}$ & 54.839$^{***}$ & 55.030$^{***}$ & 54.979$^{***}$ & 55.365$^{***}$ \\ 
##   & (1.595) & (1.507) & (1.446) & (1.304) & (1.260) \\ 
##   & & & & & \\ 
##  factor(Ec)CAN & 50.938$^{***}$ & 51.143$^{***}$ & 51.230$^{***}$ & 51.137$^{***}$ & 51.499$^{***}$ \\ 
##   & (2.070) & (2.052) & (2.078) & (2.053) & (1.961) \\ 
##   & & & & & \\ 
##  factor(Ec)DEU & 53.440$^{***}$ & 53.512$^{***}$ & 53.698$^{***}$ & 53.681$^{***}$ & 54.079$^{***}$ \\ 
##   & (1.529) & (1.478) & (1.321) & (1.263) & (1.193) \\ 
##   & & & & & \\ 
##  factor(Ec)DNK & 59.817$^{***}$ & 59.738$^{***}$ & 59.991$^{***}$ & 59.867$^{***}$ & 60.383$^{***}$ \\ 
##   & (1.642) & (1.510) & (1.406) & (1.362) & (1.321) \\ 
##   & & & & & \\ 
##  factor(Ec)ESP & 44.522$^{***}$ & 44.430$^{***}$ & 44.520$^{***}$ & 44.213$^{***}$ & 44.946$^{***}$ \\ 
##   & (2.125) & (1.974) & (1.890) & (1.847) & (1.869) \\ 
##   & & & & & \\ 
##  factor(Ec)FIN & 60.177$^{***}$ & 60.126$^{***}$ & 60.359$^{***}$ & 60.370$^{***}$ & 60.657$^{***}$ \\ 
##   & (1.557) & (1.465) & (1.389) & (1.362) & (1.327) \\ 
##   & & & & & \\ 
##  factor(Ec)GBR & 55.557$^{***}$ & 55.621$^{***}$ & 55.812$^{***}$ & 55.811$^{***}$ & 56.039$^{***}$ \\ 
##   & (1.496) & (1.388) & (1.300) & (1.242) & (1.184) \\ 
##   & & & & & \\ 
##  factor(Ec)GRC & 63.113$^{***}$ & 63.017$^{***}$ & 63.292$^{***}$ & 62.979$^{***}$ & 63.663$^{***}$ \\ 
##   & (2.547) & (2.419) & (2.380) & (2.405) & (2.339) \\ 
##   & & & & & \\ 
##  factor(Ec)IRL & 51.858$^{***}$ & 51.751$^{***}$ & 52.107$^{***}$ & 51.709$^{***}$ & 52.308$^{***}$ \\ 
##   & (1.822) & (1.730) & (1.710) & (1.637) & (1.619) \\ 
##   & & & & & \\ 
##  factor(Ec)ISL & 53.715$^{***}$ & 53.592$^{***}$ & 53.822$^{***}$ & 53.789$^{***}$ & 54.134$^{***}$ \\ 
##   & (1.791) & (1.606) & (1.503) & (1.477) & (1.407) \\ 
##   & & & & & \\ 
##  factor(Ec)ISR & 68.006$^{***}$ & 67.866$^{***}$ & 68.297$^{***}$ & 68.063$^{***}$ & 68.408$^{***}$ \\ 
##   & (2.169) & (2.101) & (2.138) & (2.064) & (2.074) \\ 
##   & & & & & \\ 
##  factor(Ec)ITA & 52.757$^{***}$ & 52.776$^{***}$ & 52.921$^{***}$ & 52.874$^{***}$ & 53.298$^{***}$ \\ 
##   & (1.913) & (1.710) & (1.651) & (1.529) & (1.550) \\ 
##   & & & & & \\ 
##  factor(Ec)NLD & 56.100$^{***}$ & 56.299$^{***}$ & 56.648$^{***}$ & 56.251$^{***}$ & 56.853$^{***}$ \\ 
##   & (1.523) & (1.382) & (1.303) & (1.092) & (1.060) \\ 
##   & & & & & \\ 
##  factor(Ec)NOR & 52.268$^{***}$ & 52.344$^{***}$ & 52.656$^{***}$ & 52.355$^{***}$ & 52.959$^{***}$ \\ 
##   & (1.753) & (1.767) & (1.634) & (1.573) & (1.519) \\ 
##   & & & & & \\ 
##  factor(Ec)NZL & 56.887$^{***}$ & 56.771$^{***}$ & 57.140$^{***}$ & 56.939$^{***}$ & 57.406$^{***}$ \\ 
##   & (2.148) & (2.124) & (2.010) & (1.953) & (1.951) \\ 
##   & & & & & \\ 
##  factor(Ec)PRT & 54.725$^{***}$ & 54.737$^{***}$ & 54.919$^{***}$ & 54.899$^{***}$ & 55.463$^{***}$ \\ 
##   & (2.694) & (2.586) & (2.535) & (2.531) & (2.568) \\ 
##   & & & & & \\ 
##  factor(Ec)SWE & 60.908$^{***}$ & 61.060$^{***}$ & 61.336$^{***}$ & 61.075$^{***}$ & 61.737$^{***}$ \\ 
##   & (2.521) & (2.430) & (2.237) & (2.210) & (2.012) \\ 
##   & & & & & \\ 
## \hline \\[-1.8ex] 
## Observations & 302 & 302 & 302 & 302 & 302 \\ 
## R$^{2}$ & 0.988 & 0.988 & 0.988 & 0.988 & 0.988 \\ 
## Adjusted R$^{2}$ & 0.987 & 0.987 & 0.987 & 0.987 & 0.987 \\ 
## Residual Std. Error (df = 279) & 6.360 & 6.375 & 6.388 & 6.374 & 6.401 \\ 
## F Statistic (df = 23; 279) & 991.169$^{***}$ & 986.412$^{***}$ & 982.447$^{***}$ & 986.694$^{***}$ & 978.313$^{***}$ \\ 
## \hline 
## \hline \\[-1.8ex] 
## \textit{Note:}  & \multicolumn{5}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
## \end{tabular} 
## \end{table}
```

``` r
##THEORY CMP CATEGORIES - ENVIRONMENTAL P. - ALTERNATIVE THRESHOLDS:----

##Table D12##
##starting value for thresholds -4
#time variables:
t0=-4#starting value for thresholds (-4,-2,0,2,4)
# dc$time1=ifelse(dc$time<=10+t0,1,0)
dc$time2=ifelse(dc$time>10+t0&dc$time<=20+t0,1,0)
dc$time3=ifelse(dc$time>20+t0&dc$time<=30+t0,1,0)
dc$time4=ifelse(dc$time>30+t0&dc$time<=40+t0,1,0)
dc$time5=ifelse(dc$time>40+t0&dc$time<=50+t0,1,0)
dc$time6=ifelse(dc$time>50+t0,1,0)
#regression:
Lp5_m4=lm(per501~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,weights=pervote)
LMp5_m4=lm_robust(per501~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,cluster=i,weights=pervote)
#plots (median cty):
# tikz(paste0("plot_","LMp5_m4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Environmental Protection") +xlab("Year") +ylab("estimated share") + coord_cartesian(ylim=c(0.0001,15)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(15-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dydc_per) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_m4,-4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_m4,-4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_m4,-4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_m4,-4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_m4,-4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_m4,-4,6)) )
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-8.png)

``` r
# dev.off()
#table (hypothesis testing):
LMp5_m4$r.squared
```

```
## [1] 0.6509888
```

``` r
LMp5_m4$nobs
```

```
## [1] 299
```

``` r
c(LMp5_m4$coefficients["time2"],LMp5_m4$std.error["time2"],LMp5_m4$p.value["time2"])#t2-t1=time2
```

```
##      time2      time2      time2 
## 1.74241180 0.84719756 0.04938166
```

``` r
Ztestfun(LMp5_m4,2,3)
```

```
##     time3               time3 
## 1.0844866 1.0340115 0.2942634
```

``` r
Ztestfun(LMp5_m4,3,4)
```

```
##        time4                     time4 
## 5.088463e+00 1.285161e+00 7.513958e-05
```

``` r
Ztestfun(LMp5_m4,4,5)
```

```
##     time5               time5 
## 0.3586420 1.8800579 0.8487127
```

``` r
Ztestfun(LMp5_m4,5,6)
```

```
##     time6               time6 
## 0.8475815 1.8935034 0.6544231
```

``` r
##starting value for thresholds -2
#time variables:
t0=-2#starting value for thresholds (-4,-2,0,2,4)
# dc$time1=ifelse(dc$time<=10+t0,1,0)
dc$time2=ifelse(dc$time>10+t0&dc$time<=20+t0,1,0)
dc$time3=ifelse(dc$time>20+t0&dc$time<=30+t0,1,0)
dc$time4=ifelse(dc$time>30+t0&dc$time<=40+t0,1,0)
dc$time5=ifelse(dc$time>40+t0&dc$time<=50+t0,1,0)
dc$time6=ifelse(dc$time>50+t0,1,0)
#regression:
Lp5_m2=lm(per501~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,weights=pervote)
LMp5_m2=lm_robust(per501~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,cluster=i,weights=pervote)
#plots (median cty):
# tikz(paste0("plot_","LMp5_m2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Environmental Protection") +xlab("Year") +ylab("estimated share") + coord_cartesian(ylim=c(0.0001,15)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(15-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dydc_per) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_m2,-2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_m2,-2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_m2,-2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_m2,-2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_m2,-2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_m2,-2,6)) )
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-9.png)

``` r
# dev.off()
#table (hypothesis testing):
LMp5_m2$r.squared
```

```
## [1] 0.6512232
```

``` r
LMp5_m2$nobs
```

```
## [1] 299
```

``` r
c(LMp5_m2$coefficients["time2"],LMp5_m2$std.error["time2"],LMp5_m2$p.value["time2"])#t2-t1=time2
```

```
##      time2      time2      time2 
## 1.81141089 0.81493787 0.03419647
```

``` r
Ztestfun(LMp5_m2,2,3)
```

```
##      time3                 time3 
## 1.77190782 1.00365844 0.07748833
```

``` r
Ztestfun(LMp5_m2,3,4)
```

```
##       time4                   time4 
## 4.407374947 1.348524485 0.001081978
```

``` r
Ztestfun(LMp5_m2,4,5)
```

```
##     time5               time5 
## 1.1346362 1.8586401 0.5415533
```

``` r
Ztestfun(LMp5_m2,5,6)
```

```
##       time6                   time6 
## -0.05386608  1.83359510  0.97656367
```

``` r
##starting value for thresholds 2
#time variables:
t0=2#starting value for thresholds (-4,-2,0,2,4)
# dc$time1=ifelse(dc$time<=10+t0,1,0)
dc$time2=ifelse(dc$time>10+t0&dc$time<=20+t0,1,0)
dc$time3=ifelse(dc$time>20+t0&dc$time<=30+t0,1,0)
dc$time4=ifelse(dc$time>30+t0&dc$time<=40+t0,1,0)
dc$time5=ifelse(dc$time>40+t0&dc$time<=50+t0,1,0)
dc$time6=ifelse(dc$time>50+t0,1,0)
#regression:
Lp5_2=lm(per501~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,weights=pervote)
LMp5_2=lm_robust(per501~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,cluster=i,weights=pervote)
#plots (median cty):
# tikz(paste0("plot_","LMp5_2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Environmental Protection") +xlab("Year") +ylab("estimated share") + coord_cartesian(ylim=c(0.0001,15)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(15-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dydc_per) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_2,2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_2,2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_2,2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_2,2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_2,2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_2,2,6)) )
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-10.png)

``` r
# dev.off()
#table (hypothesis testing):
LMp5_2$r.squared
```

```
## [1] 0.6527449
```

``` r
LMp5_2$nobs
```

```
## [1] 299
```

``` r
c(LMp5_2$coefficients["time2"],LMp5_2$std.error["time2"],LMp5_2$p.value["time2"])#t2-t1=time2
```

```
##      time2      time2      time2 
## 1.28450487 0.70829167 0.07930572
```

``` r
Ztestfun(LMp5_2,2,3)
```

```
##        time3                     time3 
## 4.739530e+00 1.032928e+00 4.465646e-06
```

``` r
Ztestfun(LMp5_2,3,4)
```

```
##     time4               time4 
## 1.3140801 1.5122894 0.3848831
```

``` r
Ztestfun(LMp5_2,4,5)
```

```
##     time5               time5 
## 0.4829003 1.7865108 0.7869267
```

``` r
Ztestfun(LMp5_2,5,6)
```

```
##     time6               time6 
## 1.3076238 1.6755741 0.4351534
```

``` r
##starting value for thresholds 4
#time variables:
t0=4#starting value for thresholds (-4,-2,0,2,4)
# dc$time1=ifelse(dc$time<=10+t0,1,0)
dc$time2=ifelse(dc$time>10+t0&dc$time<=20+t0,1,0)
dc$time3=ifelse(dc$time>20+t0&dc$time<=30+t0,1,0)
dc$time4=ifelse(dc$time>30+t0&dc$time<=40+t0,1,0)
dc$time5=ifelse(dc$time>40+t0&dc$time<=50+t0,1,0)
dc$time6=ifelse(dc$time>50+t0,1,0)
#regression:
Lp5_4=lm(per501~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,weights=pervote)
LMp5_4=lm_robust(per501~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,cluster=i,weights=pervote)
#plots (median cty):
# tikz(paste0("plot_","LMp5_4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Environmental Protection") +xlab("Year") +ylab("estimated share") + coord_cartesian(ylim=c(0.0001,15)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(15-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dydc_per) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_4,4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_4,4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_4,4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_4,4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_4,4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp5_4,4,6)) )
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-11.png)

``` r
# dev.off()
#table (hypothesis testing):
LMp5_4$r.squared
```

```
## [1] 0.6485597
```

``` r
LMp5_4$nobs
```

```
## [1] 299
```

``` r
c(LMp5_4$coefficients["time2"],LMp5_4$std.error["time2"],LMp5_4$p.value["time2"])#t2-t1=time2
```

```
##      time2      time2      time2 
## 1.65818966 0.68261034 0.02016413
```

``` r
Ztestfun(LMp5_4,2,3)
```

```
##        time3                     time3 
## 5.458359e+00 1.251528e+00 1.292599e-05
```

``` r
Ztestfun(LMp5_4,3,4)
```

```
##     time4               time4 
## 0.2087719 1.7645344 0.9058176
```

``` r
Ztestfun(LMp5_4,4,5)
```

```
##     time5               time5 
## 0.2525127 1.8291738 0.8902029
```

``` r
Ztestfun(LMp5_4,5,6)
```

```
##     time6               time6 
## 1.2417132 1.7486335 0.4776391
```

``` r
##Table I10##
##table full results:
stargazer(Lp5_m4,Lp5_m2,L_dc_10_per501,Lp5_2,Lp5_4,
          se = list(LMp5_m4$std.error,LMp5_m2$std.error,LM_dc_10_per501$std.error,LMp5_2$std.error,LMp5_4$std.error))
```

```
## 
## % Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
## % Date and time: Thu, Dec 04, 2025 - 11:03:52
## \begin{table}[!htbp] \centering 
##   \caption{} 
##   \label{} 
## \begin{tabular}{@{\extracolsep{5pt}}lccccc} 
## \\[-1.8ex]\hline 
## \hline \\[-1.8ex] 
##  & \multicolumn{5}{c}{\textit{Dependent variable:}} \\ 
## \cline{2-6} 
## \\[-1.8ex] & \multicolumn{5}{c}{per501} \\ 
## \\[-1.8ex] & (1) & (2) & (3) & (4) & (5)\\ 
## \hline \\[-1.8ex] 
##  time2 & 1.742$^{**}$ & 1.811$^{**}$ & 2.091$^{***}$ & 1.285$^{*}$ & 1.658$^{**}$ \\ 
##   & (0.847) & (0.815) & (0.680) & (0.708) & (0.683) \\ 
##   & & & & & \\ 
##  time3 & 2.827$^{***}$ & 3.583$^{***}$ & 5.410$^{***}$ & 6.024$^{***}$ & 7.117$^{***}$ \\ 
##   & (0.908) & (0.872) & (0.904) & (0.933) & (1.158) \\ 
##   & & & & & \\ 
##  time4 & 7.915$^{***}$ & 7.991$^{***}$ & 8.541$^{***}$ & 7.338$^{***}$ & 7.325$^{***}$ \\ 
##   & (1.175) & (1.243) & (1.403) & (1.309) & (1.421) \\ 
##   & & & & & \\ 
##  time5 & 8.274$^{***}$ & 9.125$^{***}$ & 8.345$^{***}$ & 7.821$^{***}$ & 7.578$^{***}$ \\ 
##   & (1.621) & (1.536) & (1.390) & (1.351) & (1.273) \\ 
##   & & & & & \\ 
##  time6 & 9.122$^{***}$ & 9.071$^{***}$ & 9.397$^{***}$ & 9.129$^{***}$ & 8.820$^{***}$ \\ 
##   & (1.235) & (1.229) & (1.055) & (1.158) & (1.320) \\ 
##   & & & & & \\ 
##  factor(Ec)AUS & $-$1.245 & $-$1.141 & $-$1.243 & $-$0.816 & $-$0.336 \\ 
##   & (1.097) & (1.066) & (1.016) & (0.934) & (0.877) \\ 
##   & & & & & \\ 
##  factor(Ec)AUT & 2.733$^{**}$ & 2.469$^{**}$ & 2.621$^{***}$ & 3.100$^{***}$ & 3.552$^{***}$ \\ 
##   & (1.120) & (1.064) & (0.867) & (0.945) & (1.066) \\ 
##   & & & & & \\ 
##  factor(Ec)CAN & 0.941 & 1.106 & 1.103 & 1.574$^{*}$ & 1.913$^{**}$ \\ 
##   & (0.963) & (0.945) & (0.830) & (0.907) & (0.908) \\ 
##   & & & & & \\ 
##  factor(Ec)DEU & 1.137 & 1.071 & 1.386$^{**}$ & 1.991$^{**}$ & 2.004$^{**}$ \\ 
##   & (0.904) & (0.949) & (0.702) & (0.829) & (0.854) \\ 
##   & & & & & \\ 
##  factor(Ec)DNK & $-$0.716 & 0.107 & $-$0.084 & 0.315 & 0.183 \\ 
##   & (1.611) & (1.765) & (1.785) & (1.654) & (1.541) \\ 
##   & & & & & \\ 
##  factor(Ec)ESP & $-$1.002 & $-$1.169 & $-$0.995 & $-$0.263 & $-$0.394 \\ 
##   & (1.021) & (0.982) & (0.906) & (0.837) & (0.848) \\ 
##   & & & & & \\ 
##  factor(Ec)FIN & 6.113$^{***}$ & 6.040$^{***}$ & 6.246$^{***}$ & 6.906$^{***}$ & 6.877$^{***}$ \\ 
##   & (2.264) & (2.277) & (2.189) & (2.243) & (2.242) \\ 
##   & & & & & \\ 
##  factor(Ec)GBR & $-$0.385 & $-$0.257 & $-$0.141 & 0.251 & 0.521 \\ 
##   & (1.001) & (0.994) & (1.068) & (1.016) & (0.887) \\ 
##   & & & & & \\ 
##  factor(Ec)GRC & $-$4.436$^{***}$ & $-$4.576$^{***}$ & $-$4.409$^{***}$ & $-$3.588$^{***}$ & $-$3.820$^{***}$ \\ 
##   & (1.320) & (1.292) & (1.429) & (1.268) & (1.153) \\ 
##   & & & & & \\ 
##  factor(Ec)IRL & 2.261 & 2.475 & 2.643 & 3.174 & 3.249$^{*}$ \\ 
##   & (2.270) & (2.229) & (2.029) & (1.977) & (1.935) \\ 
##   & & & & & \\ 
##  factor(Ec)ISL & 0.376 & 0.605 & 0.478 & 1.104 & 1.455 \\ 
##   & (1.444) & (1.296) & (1.284) & (1.402) & (1.394) \\ 
##   & & & & & \\ 
##  factor(Ec)ISR & $-$5.030$^{***}$ & $-$4.986$^{***}$ & $-$5.219$^{***}$ & $-$4.774$^{***}$ & $-$4.435$^{***}$ \\ 
##   & (1.105) & (1.089) & (0.973) & (0.979) & (1.014) \\ 
##   & & & & & \\ 
##  factor(Ec)ITA & 0.036 & 0.400 & 0.510 & 1.190 & 1.272 \\ 
##   & (2.377) & (2.373) & (2.204) & (2.228) & (2.182) \\ 
##   & & & & & \\ 
##  factor(Ec)NLD & 1.098 & 1.331$^{*}$ & 1.395$^{*}$ & 1.938$^{**}$ & 1.954$^{**}$ \\ 
##   & (0.795) & (0.760) & (0.730) & (0.785) & (0.766) \\ 
##   & & & & & \\ 
##  factor(Ec)NOR & 4.360$^{***}$ & 4.130$^{***}$ & 4.344$^{***}$ & 4.997$^{***}$ & 5.050$^{***}$ \\ 
##   & (1.292) & (1.325) & (1.326) & (1.283) & (1.274) \\ 
##   & & & & & \\ 
##  factor(Ec)NZL & 1.378 & 1.670$^{*}$ & 1.432 & 2.112$^{**}$ & 2.270$^{**}$ \\ 
##   & (1.047) & (0.965) & (0.911) & (0.835) & (0.931) \\ 
##   & & & & & \\ 
##  factor(Ec)PRT & 0.852 & 0.786 & 0.654 & 1.055 & 1.274 \\ 
##   & (8.764) & (8.458) & (8.882) & (9.191) & (8.920) \\ 
##   & & & & & \\ 
##  factor(Ec)SWE & 12.782$^{***}$ & 12.884$^{***}$ & 12.727$^{***}$ & 13.457$^{***}$ & 13.476$^{***}$ \\ 
##   & (2.308) & (2.446) & (2.337) & (2.334) & (2.249) \\ 
##   & & & & & \\ 
## \hline \\[-1.8ex] 
## Observations & 299 & 299 & 299 & 299 & 299 \\ 
## R$^{2}$ & 0.651 & 0.651 & 0.655 & 0.653 & 0.649 \\ 
## Adjusted R$^{2}$ & 0.622 & 0.622 & 0.626 & 0.624 & 0.619 \\ 
## Residual Std. Error (df = 276) & 18.829 & 18.823 & 18.717 & 18.782 & 18.895 \\ 
## F Statistic (df = 23; 276) & 22.383$^{***}$ & 22.406$^{***}$ & 22.795$^{***}$ & 22.557$^{***}$ & 22.145$^{***}$ \\ 
## \hline 
## \hline \\[-1.8ex] 
## \textit{Note:}  & \multicolumn{5}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
## \end{tabular} 
## \end{table}
```

``` r
##THEORY CMP CATEGORIES - EQUALITY P. - ALTERNATIVE THRESHOLDS:----

##Table D13##
##starting value for thresholds -4
#time variables:
t0=-4#starting value for thresholds (-4,-2,0,2,4)
# dc$time1=ifelse(dc$time<=10+t0,1,0)
dc$time2=ifelse(dc$time>10+t0&dc$time<=20+t0,1,0)
dc$time3=ifelse(dc$time>20+t0&dc$time<=30+t0,1,0)
dc$time4=ifelse(dc$time>30+t0&dc$time<=40+t0,1,0)
dc$time5=ifelse(dc$time>40+t0&dc$time<=50+t0,1,0)
dc$time6=ifelse(dc$time>50+t0,1,0)
#regression:
Lp3_m4=lm(per503~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,weights=pervote)
LMp3_m4=lm_robust(per503~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,cluster=i,weights=pervote)
#plots (median cty):
# tikz(paste0("plot_","LMp3_m4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Equality, Positive") +xlab("Year") +ylab("estimated share") + coord_cartesian(ylim=c(0.0001,15)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(15-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dydc_per) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_m4,-4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_m4,-4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_m4,-4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_m4,-4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_m4,-4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_m4,-4,6)) )
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-12.png)

``` r
# dev.off()
LMp3_m4$r.squared
```

```
## [1] 0.7448784
```

``` r
LMp3_m4$nobs
```

```
## [1] 299
```

``` r
c(LMp3_m4$coefficients["time2"],LMp3_m4$std.error["time2"],LMp3_m4$p.value["time2"])#t2-t1=time2
```

```
##      time2      time2      time2 
## 1.90325013 1.03409198 0.07658096
```

``` r
Ztestfun(LMp3_m4,2,3)
```

```
##      time3                 time3 
## -0.1264446  1.1865442  0.9151337
```

``` r
Ztestfun(LMp3_m4,3,4)
```

```
##     time4               time4 
## 1.3250148 1.2211220 0.2778863
```

``` r
Ztestfun(LMp3_m4,4,5)
```

```
##     time5               time5 
## 2.3990754 1.5701716 0.1265358
```

``` r
Ztestfun(LMp3_m4,5,6)
```

```
##      time6                 time6 
## -0.1134011  1.5167849  0.9404024
```

``` r
##starting value for thresholds -2
#time variables:
t0=-2#starting value for thresholds (-4,-2,0,2,4)
# dc$time1=ifelse(dc$time<=10+t0,1,0)
dc$time2=ifelse(dc$time>10+t0&dc$time<=20+t0,1,0)
dc$time3=ifelse(dc$time>20+t0&dc$time<=30+t0,1,0)
dc$time4=ifelse(dc$time>30+t0&dc$time<=40+t0,1,0)
dc$time5=ifelse(dc$time>40+t0&dc$time<=50+t0,1,0)
dc$time6=ifelse(dc$time>50+t0,1,0)
#regression:
Lp3_m2=lm(per503~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,weights=pervote)
LMp3_m2=lm_robust(per503~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,cluster=i,weights=pervote)
#plots (median cty):
# tikz(paste0("plot_","LMp3_m2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Equality, Positive") +xlab("Year") +ylab("estimated share") + coord_cartesian(ylim=c(0.0001,15)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(15-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dydc_per) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_m2,-2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_m2,-2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_m2,-2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_m2,-2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_m2,-2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_m2,-2,6)) )
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-13.png)

``` r
# dev.off()
LMp3_m2$r.squared
```

```
## [1] 0.7403902
```

``` r
LMp3_m2$nobs
```

```
## [1] 299
```

``` r
c(LMp3_m2$coefficients["time2"],LMp3_m2$std.error["time2"],LMp3_m2$p.value["time2"])#t2-t1=time2
```

```
##     time2     time2     time2 
## 1.2568431 0.9800729 0.2098701
```

``` r
Ztestfun(LMp3_m2,2,3)
```

```
##     time3               time3 
## 0.9429654 1.1206002 0.4000777
```

``` r
Ztestfun(LMp3_m2,3,4)
```

```
##     time4               time4 
## 1.1907157 1.3343907 0.3722165
```

``` r
Ztestfun(LMp3_m2,4,5)
```

```
##     time5               time5 
## 1.4819525 1.6836940 0.3787622
```

``` r
Ztestfun(LMp3_m2,5,6)
```

```
##     time6               time6 
## 0.3564330 1.5229362 0.8149513
```

``` r
##starting value for thresholds 2
#time variables:
t0=2#starting value for thresholds (-4,-2,0,2,4)
# dc$time1=ifelse(dc$time<=10+t0,1,0)
dc$time2=ifelse(dc$time>10+t0&dc$time<=20+t0,1,0)
dc$time3=ifelse(dc$time>20+t0&dc$time<=30+t0,1,0)
dc$time4=ifelse(dc$time>30+t0&dc$time<=40+t0,1,0)
dc$time5=ifelse(dc$time>40+t0&dc$time<=50+t0,1,0)
dc$time6=ifelse(dc$time>50+t0,1,0)
#regression:
Lp3_2=lm(per503~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,weights=pervote)
LMp3_2=lm_robust(per503~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,cluster=i,weights=pervote)
#plots (median cty):
# tikz(paste0("plot_","LMp3_2.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Equality, Positive") +xlab("Year") +ylab("estimated share") + coord_cartesian(ylim=c(0.0001,15)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(15-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dydc_per) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_2,2,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_2,2,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_2,2,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_2,2,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_2,2,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_2,2,6)) )
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-14.png)

``` r
# dev.off()
LMp3_2$r.squared
```

```
## [1] 0.7478582
```

``` r
LMp3_2$nobs
```

```
## [1] 299
```

``` r
c(LMp3_2$coefficients["time2"],LMp3_2$std.error["time2"],LMp3_2$p.value["time2"])#t2-t1=time2
```

```
##     time2     time2     time2 
## 1.1361631 0.8324198 0.1819747
```

``` r
Ztestfun(LMp3_2,2,3)
```

```
##     time3               time3 
## 0.9335004 0.9954463 0.3483623
```

``` r
Ztestfun(LMp3_2,3,4)
```

```
##     time4               time4 
## 2.9227187 1.4054115 0.0375606
```

``` r
Ztestfun(LMp3_2,4,5)
```

```
##      time5                 time5 
## -1.4100606  1.5475079  0.3621997
```

``` r
Ztestfun(LMp3_2,5,6)
```

```
##     time6               time6 
## 1.6539481 1.2839497 0.1976861
```

``` r
##starting value for thresholds 4
#time variables:
t0=4#starting value for thresholds (-4,-2,0,2,4)
# dc$time1=ifelse(dc$time<=10+t0,1,0)
dc$time2=ifelse(dc$time>10+t0&dc$time<=20+t0,1,0)
dc$time3=ifelse(dc$time>20+t0&dc$time<=30+t0,1,0)
dc$time4=ifelse(dc$time>30+t0&dc$time<=40+t0,1,0)
dc$time5=ifelse(dc$time>40+t0&dc$time<=50+t0,1,0)
dc$time6=ifelse(dc$time>50+t0,1,0)
#regression:
Lp3_4=lm(per503~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,weights=pervote)
LMp3_4=lm_robust(per503~time2+time3+time4+time5+time6+factor(Ec)-1,data=dc,cluster=i,weights=pervote)
#plots (median cty):
# tikz(paste0("plot_","LMp3_4.tex"),width=4, height=3)
plot( ggplot() +ggtitle("Equality, Positive") +xlab("Year") +ylab("estimated share") + coord_cartesian(ylim=c(0.0001,15)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(15-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dydc_per) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_4,4,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_4,4,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_4,4,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_4,4,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_4,4,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LM_dc(LMp3_4,4,6)) )
```

![plot of chunk unnamed-chunk-1](figure/unnamed-chunk-1-15.png)

``` r
# dev.off()
LMp3_4$r.squared
```

```
## [1] 0.7506615
```

``` r
LMp3_4$nobs
```

```
## [1] 299
```

``` r
c(LMp3_4$coefficients["time2"],LMp3_4$std.error["time2"],LMp3_4$p.value["time2"])#t2-t1=time2
```

```
##     time2     time2     time2 
## 1.1034702 0.7856555 0.1685935
```

``` r
Ztestfun(LMp3_4,2,3)
```

```
##     time3               time3 
## 0.5063089 0.9893108 0.6088054
```

``` r
Ztestfun(LMp3_4,3,4)
```

```
##       time4                   time4 
## 3.995236297 1.408965490 0.004574236
```

``` r
Ztestfun(LMp3_4,4,5)
```

```
##      time5                 time5 
## -1.8380485  1.5307805  0.2298573
```

``` r
Ztestfun(LMp3_4,5,6)
```

```
##     time6               time6 
## 1.1443490 1.3502267 0.3967033
```

``` r
##Table I11##
##table full results:
stargazer(Lp3_m4,Lp3_m2,L_dc_10_per503,Lp3_2,Lp3_4,
          se = list(LMp3_m4$std.error,LMp3_m2$std.error,LM_dc_10_per503$std.error,LMp3_2$std.error,LMp3_4$std.error))
```

```
## 
## % Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
## % Date and time: Thu, Dec 04, 2025 - 11:03:53
## \begin{table}[!htbp] \centering 
##   \caption{} 
##   \label{} 
## \begin{tabular}{@{\extracolsep{5pt}}lccccc} 
## \\[-1.8ex]\hline 
## \hline \\[-1.8ex] 
##  & \multicolumn{5}{c}{\textit{Dependent variable:}} \\ 
## \cline{2-6} 
## \\[-1.8ex] & \multicolumn{5}{c}{per503} \\ 
## \\[-1.8ex] & (1) & (2) & (3) & (4) & (5)\\ 
## \hline \\[-1.8ex] 
##  time2 & 1.903$^{*}$ & 1.257 & 0.913 & 1.136 & 1.103 \\ 
##   & (1.034) & (0.980) & (0.875) & (0.832) & (0.786) \\ 
##   & & & & & \\ 
##  time3 & 1.777$^{*}$ & 2.200$^{**}$ & 2.110$^{**}$ & 2.070$^{***}$ & 1.610$^{**}$ \\ 
##   & (0.965) & (0.913) & (0.867) & (0.789) & (0.810) \\ 
##   & & & & & \\ 
##  time4 & 3.102$^{***}$ & 3.391$^{***}$ & 4.045$^{***}$ & 4.992$^{***}$ & 5.605$^{***}$ \\ 
##   & (1.066) & (1.207) & (1.332) & (1.270) & (1.258) \\ 
##   & & & & & \\ 
##  time5 & 5.501$^{***}$ & 4.872$^{***}$ & 4.418$^{***}$ & 3.582$^{***}$ & 3.767$^{***}$ \\ 
##   & (1.381) & (1.380) & (1.269) & (1.072) & (1.043) \\ 
##   & & & & & \\ 
##  time6 & 5.387$^{***}$ & 5.229$^{***}$ & 4.960$^{***}$ & 5.236$^{***}$ & 4.911$^{***}$ \\ 
##   & (1.017) & (0.992) & (1.010) & (0.898) & (1.005) \\ 
##   & & & & & \\ 
##  factor(Ec)AUS & 1.661$^{*}$ & 1.925$^{**}$ & 2.176$^{**}$ & 2.040$^{***}$ & 2.381$^{***}$ \\ 
##   & (0.900) & (0.937) & (0.881) & (0.749) & (0.773) \\ 
##   & & & & & \\ 
##  factor(Ec)AUT & 5.972$^{***}$ & 6.149$^{***}$ & 6.602$^{***}$ & 6.628$^{***}$ & 6.829$^{***}$ \\ 
##   & (1.759) & (1.719) & (1.668) & (1.518) & (1.510) \\ 
##   & & & & & \\ 
##  factor(Ec)CAN & 2.288$^{*}$ & 2.697$^{**}$ & 3.018$^{***}$ & 3.095$^{***}$ & 3.183$^{***}$ \\ 
##   & (1.224) & (1.143) & (1.117) & (1.035) & (1.103) \\ 
##   & & & & & \\ 
##  factor(Ec)DEU & 3.576$^{***}$ & 3.880$^{***}$ & 4.356$^{***}$ & 4.406$^{***}$ & 4.528$^{***}$ \\ 
##   & (0.897) & (0.895) & (0.856) & (0.802) & (0.796) \\ 
##   & & & & & \\ 
##  factor(Ec)DNK & 2.262$^{*}$ & 2.646$^{**}$ & 2.971$^{**}$ & 3.043$^{**}$ & 3.370$^{***}$ \\ 
##   & (1.303) & (1.347) & (1.286) & (1.182) & (1.182) \\ 
##   & & & & & \\ 
##  factor(Ec)ESP & 0.968 & 0.966 & 1.297 & 1.057 & 1.331 \\ 
##   & (0.970) & (0.990) & (0.991) & (0.956) & (0.982) \\ 
##   & & & & & \\ 
##  factor(Ec)FIN & 6.874$^{***}$ & 7.113$^{***}$ & 7.488$^{***}$ & 7.631$^{***}$ & 7.557$^{***}$ \\ 
##   & (1.533) & (1.520) & (1.605) & (1.507) & (1.521) \\ 
##   & & & & & \\ 
##  factor(Ec)GBR & 2.286 & 2.477$^{*}$ & 2.847$^{*}$ & 3.125$^{**}$ & 3.365$^{**}$ \\ 
##   & (1.489) & (1.445) & (1.538) & (1.423) & (1.318) \\ 
##   & & & & & \\ 
##  factor(Ec)GRC & 1.429 & 1.452 & 1.892$^{*}$ & 2.129$^{**}$ & 2.324$^{**}$ \\ 
##   & (1.152) & (1.143) & (1.105) & (0.917) & (0.949) \\ 
##   & & & & & \\ 
##  factor(Ec)IRL & 3.814$^{**}$ & 4.210$^{**}$ & 4.575$^{**}$ & 4.609$^{***}$ & 4.759$^{**}$ \\ 
##   & (1.713) & (1.767) & (1.803) & (1.771) & (1.909) \\ 
##   & & & & & \\ 
##  factor(Ec)ISL & 5.273$^{***}$ & 5.569$^{***}$ & 5.859$^{***}$ & 5.991$^{***}$ & 6.140$^{***}$ \\ 
##   & (1.279) & (1.259) & (1.248) & (1.228) & (1.179) \\ 
##   & & & & & \\ 
##  factor(Ec)ISR & 9.377$^{***}$ & 9.541$^{***}$ & 9.766$^{***}$ & 9.656$^{***}$ & 9.813$^{***}$ \\ 
##   & (2.501) & (2.479) & (2.525) & (2.564) & (2.551) \\ 
##   & & & & & \\ 
##  factor(Ec)ITA & $-$1.996 & $-$1.336 & $-$1.146 & $-$0.739 & $-$0.696 \\ 
##   & (1.459) & (1.426) & (1.334) & (1.146) & (1.198) \\ 
##   & & & & & \\ 
##  factor(Ec)NLD & 6.748$^{***}$ & 7.398$^{***}$ & 7.552$^{***}$ & 7.637$^{***}$ & 7.600$^{***}$ \\ 
##   & (1.459) & (1.606) & (1.543) & (1.509) & (1.521) \\ 
##   & & & & & \\ 
##  factor(Ec)NOR & 4.606$^{***}$ & 4.922$^{***}$ & 5.244$^{***}$ & 5.165$^{***}$ & 5.564$^{***}$ \\ 
##   & (1.117) & (1.101) & (1.084) & (1.036) & (1.066) \\ 
##   & & & & & \\ 
##  factor(Ec)NZL & 0.608 & 0.805 & 1.058 & 1.100 & 1.454$^{*}$ \\ 
##   & (0.974) & (0.974) & (0.869) & (0.744) & (0.782) \\ 
##   & & & & & \\ 
##  factor(Ec)PRT & 0.607 & 0.787 & 1.166 & 0.941 & 1.148 \\ 
##   & (2.768) & (2.804) & (3.048) & (3.125) & (2.846) \\ 
##   & & & & & \\ 
##  factor(Ec)SWE & 5.850$^{***}$ & 6.191$^{***}$ & 6.459$^{***}$ & 6.514$^{***}$ & 6.904$^{***}$ \\ 
##   & (1.505) & (1.427) & (1.425) & (1.374) & (1.362) \\ 
##   & & & & & \\ 
## \hline \\[-1.8ex] 
## Observations & 299 & 299 & 299 & 299 & 299 \\ 
## R$^{2}$ & 0.745 & 0.740 & 0.743 & 0.748 & 0.751 \\ 
## Adjusted R$^{2}$ & 0.724 & 0.719 & 0.721 & 0.727 & 0.730 \\ 
## Residual Std. Error (df = 276) & 14.331 & 14.456 & 14.391 & 14.247 & 14.167 \\ 
## F Statistic (df = 23; 276) & 35.036$^{***}$ & 34.223$^{***}$ & 34.645$^{***}$ & 35.592$^{***}$ & 36.127$^{***}$ \\ 
## \hline 
## \hline \\[-1.8ex] 
## \textit{Note:}  & \multicolumn{5}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
## \end{tabular} 
## \end{table}
```

``` r
#RC WITH DISTANCE VOTER-PARTY - 10Y SEGMENTS:----

#confidence interval functions:
CI.PlLllseslrd10fun=function(CLC,t0,pe){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=4)#Pl:
  for (t in 1:59) {
    # t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    CI.PlLl[t,1]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4-
      (CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+
      1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]-
      2*1*1*vcov(CLC)["Pl_ISL","Ll_ISL"]+2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  if (pe==1) {CI.PlLl=CI.PlLl[(1+t0):(10+t0),]}
  if (pe==2) {CI.PlLl=CI.PlLl[(11+t0):(20+t0),]}
  if (pe==3) {CI.PlLl=CI.PlLl[(21+t0):(30+t0),]}
  if (pe==4) {CI.PlLl=CI.PlLl[(31+t0):(40+t0),]}
  if (pe==5) {CI.PlLl=CI.PlLl[(41+t0):(50+t0),]}
  if (pe==6) {CI.PlLl=CI.PlLl[(51+t0):59,]}
  # CI.PlLl=CI.PlLl[19:59,]
  CI.PlLl
}

#Z-test functions:
ZtestfunT12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2)]-CLC$coefficients[paste0("Ll:time",2)]#mean
  v=vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2)]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunT=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunTT12=function(CLC1,CLC2){
  m=(CLC1$coefficients[paste0("Pl:time",2)]-CLC1$coefficients[paste0("Ll:time",2)]-
       CLC2$coefficients[paste0("Pl:time",2)]+CLC2$coefficients[paste0("Ll:time",2)])#mean
  v=vcov(CLC1)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC1)[paste0("Ll:time",2),paste0("Ll:time",2)]+
    vcov(CLC2)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC2)[paste0("Ll:time",2),paste0("Ll:time",2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunTT=function(CLC1,CLC2,per1,per2){
  m=-(CLC1$coefficients[paste0("Pl:time",per1)]-CLC1$coefficients[paste0("Ll:time",per1)]-
        CLC2$coefficients[paste0("Pl:time",per1)]+CLC2$coefficients[paste0("Ll:time",per1)]-
        CLC1$coefficients[paste0("Pl:time",per2)]+CLC1$coefficients[paste0("Ll:time",per2)]+
        CLC2$coefficients[paste0("Pl:time",per2)]-CLC2$coefficients[paste0("Ll:time",per2)])#mean
  v=vcov(CLC1)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC1)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC2)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC2)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC1)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC1)[paste0("Ll:time",per2),paste0("Ll:time",per2)]+
    vcov(CLC2)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC2)[paste0("Ll:time",per2),paste0("Ll:time",per2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}

#time variables:
t0=20#starting value for thresholds (16,18,20,22,24)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
CLC_lseslrd10_20=clogit(Va ~ Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+LRD
                      +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                      +strata(Esalt) ,robust=T ,data=de[!is.na(de$LRD),], weights=Rwd, method="efron")#regression
```

```
## Error in de$LRD: object of type 'closure' is not subsettable
```

``` r
names(CLC_lseslrd10_20$coefficients)[names(CLC_lseslrd10_20$coefficients)=="time2:Ll"]="Ll:time2"
```

```
## Error: object 'CLC_lseslrd10_20' not found
```

``` r
CLC_lseslrd10_20nlrd=clogit(Va ~ Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4
                        +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                        +strata(Esalt) ,robust=T ,data=de[!is.na(de$LRD),], weights=Rwd, method="efron")#regression
```

```
## Error in de$LRD: object of type 'closure' is not subsettable
```

``` r
names(CLC_lseslrd10_20nlrd$coefficients)[names(CLC_lseslrd10_20nlrd$coefficients)=="time2:Ll"]="Ll:time2"
```

```
## Error: object 'CLC_lseslrd10_20nlrd' not found
```

``` r
#plots:
#median cty:
# tikz(paste0("plot_","CLC_lseslrd10","_PlLl_20.tex"),width=4, height=3)#plot Pl-Ll:
plot( ggplot() 
      +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyLRD) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="blue", lwd=2, CI.PlLllseslrd10fun(CLC_lseslrd10_20,20,1)) +#w/ LRD
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="blue", lwd=2, CI.PlLllseslrd10fun(CLC_lseslrd10_20,20,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="blue", lwd=2, CI.PlLllseslrd10fun(CLC_lseslrd10_20,20,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="blue", lwd=2, CI.PlLllseslrd10fun(CLC_lseslrd10_20,20,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="green4", lty="44", lwd=3, CI.PlLllseslrd10fun(CLC_lseslrd10_20nlrd,20,1)) +#w/o LRD
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="green4", lty="44", lwd=3, CI.PlLllseslrd10fun(CLC_lseslrd10_20nlrd,20,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="green4", lty="44", lwd=3, CI.PlLllseslrd10fun(CLC_lseslrd10_20nlrd,20,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="green4", lty="44", lwd=3, CI.PlLllseslrd10fun(CLC_lseslrd10_20nlrd,20,4)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyLRD' not found
```

``` r
# dev.off()


##Table E1## and ##Table I13##
#table:
stargazer(CLC_lseslrd10_20,CLC_lseslrd10_20nlrd)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lseslrd10_20' not found
```

``` r
ZtestfunT12(CLC_lseslrd10_20)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lseslrd10_20' not found
```

``` r
ZtestfunT(CLC_lseslrd10_20,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lseslrd10_20' not found
```

``` r
ZtestfunT(CLC_lseslrd10_20,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lseslrd10_20' not found
```

``` r
ZtestfunT12(CLC_lseslrd10_20nlrd)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lseslrd10_20nlrd' not found
```

``` r
ZtestfunT(CLC_lseslrd10_20nlrd,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lseslrd10_20nlrd' not found
```

``` r
ZtestfunT(CLC_lseslrd10_20nlrd,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lseslrd10_20nlrd' not found
```

``` r
ZtestfunTT12(CLC_lseslrd10_20,CLC_lseslrd10_20nlrd)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lseslrd10_20' not found
```

``` r
ZtestfunTT(CLC_lseslrd10_20,CLC_lseslrd10_20nlrd,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lseslrd10_20' not found
```

``` r
ZtestfunTT(CLC_lseslrd10_20,CLC_lseslrd10_20nlrd,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lseslrd10_20' not found
```

``` r
#MEDIA - USE OF MEDIA OVER TIME:----

#data availability:
sort(unique(de$Ey[!(is.na(de$Mnwsp))]))#1979-2013
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
sort(unique(de$Ey[!(is.na(de$Mradi))]))#1979-2011
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
sort(unique(de$Ey[!(is.na(de$Mtele))]))#1979-2013
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
sort(unique(de$Ey[!(is.na(de$Minte))]))#2003:2013
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
#even if there are up to two elections before 1979, I exclude them since there are
# not enough data before 1979 and the two elections could over-influence the trend
# before 1979; however by keeping them the trends substantially do not change.

#base for density plots:
#create dataset density all data:
dyMnwsp = de[!is.na(de$Va)&!is.na(de$Pl)&!is.na(de$Ll)&!is.na(de$Mnwsp),] %>% group_by(Ey) %>% mutate(Eyn=n())#number of obs by Ey
```

```
## Error in de$Va: object of type 'closure' is not subsettable
```

``` r
dyMnwsp$Eyn=dyMnwsp$Eyn/1020288#density by Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyMnwsp' not found
```

``` r
dyMnwsp=dyMnwsp %>% group_by(Ey) %>% filter(row_number()==1)#keep only 1 obs per Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyMnwsp' not found
```

``` r
dyMradi = de[!is.na(de$Va)&!is.na(de$Pl)&!is.na(de$Ll)&!is.na(de$Mradi),] %>% group_by(Ey) %>% mutate(Eyn=n())#number of obs by Ey
```

```
## Error in de$Va: object of type 'closure' is not subsettable
```

``` r
dyMradi$Eyn=dyMradi$Eyn/1020288#density by Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyMradi' not found
```

``` r
dyMradi=dyMradi %>% group_by(Ey) %>% filter(row_number()==1)#keep only 1 obs per Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyMradi' not found
```

``` r
dyMtele = de[!is.na(de$Va)&!is.na(de$Pl)&!is.na(de$Ll)&!is.na(de$Mtele),] %>% group_by(Ey) %>% mutate(Eyn=n())#number of obs by Ey
```

```
## Error in de$Va: object of type 'closure' is not subsettable
```

``` r
dyMtele$Eyn=dyMtele$Eyn/1020288#density by Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyMtele' not found
```

``` r
dyMtele=dyMtele %>% group_by(Ey) %>% filter(row_number()==1)#keep only 1 obs per Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyMtele' not found
```

``` r
dyMinte = de[!is.na(de$Va)&!is.na(de$Pl)&!is.na(de$Ll)&!is.na(de$Minte),] %>% group_by(Ey) %>% mutate(Eyn=n())#number of obs by Ey
```

```
## Error in de$Va: object of type 'closure' is not subsettable
```

``` r
dyMinte$Eyn=dyMinte$Eyn/1020288#density by Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyMinte' not found
```

``` r
dyMinte=dyMinte %>% group_by(Ey) %>% filter(row_number()==1)#keep only 1 obs per Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyMinte' not found
```

``` r
#confidence interval functions:
CI.LMMediafun=function(LM,t0){ #function creating Confidence Interval for Med
  CI.Med=matrix(NA,nrow=59,ncol=4)#Med:
  for (t in 1:59) {
    t3=pmin(t,30+t0)
    t4=pmax(30+t0,pmin(t,40+t0))
    t5=pmax(40+t0,t)
    CI.Med[t,1]=LM$coefficients["factor(Ec)DEU"]+LM$coefficients["time3"]*t3+LM$coefficients["time4"]*t4+LM$coefficients["time5"]*t5#fitted values
    CI.Med[t,2]=1*vcov(LM)["factor(Ec)DEU","factor(Ec)DEU"]+t3^2*vcov(LM)["time3","time3"]+t4^2*vcov(LM)["time4","time4"]+t5^2*vcov(LM)["time5","time5"]+
      2*1*t3*vcov(LM)["factor(Ec)DEU","time3"]+2*1*t4*vcov(LM)["factor(Ec)DEU","time4"]+2*1*t5*vcov(LM)["factor(Ec)DEU","time5"]+
      2*t3*t4*vcov(LM)["time3","time4"]+2*t3*t5*vcov(LM)["time3","time5"]+
      2*t4*t5*vcov(LM)["time4","time5"]#Variance
    CI.Med[t,3]=CI.Med[t,1]-qnorm(0.975)*sqrt(CI.Med[t,2])#95% CI lower
    CI.Med[t,4]=CI.Med[t,1]+qnorm(0.975)*sqrt(CI.Med[t,2])#95% CI upper
  }
  CI.Med=as.data.frame(CI.Med)
  CI.Med$t=c(1961:2019)
  CI.Med=CI.Med[19:53,]
  CI.Med
}
CI.LMMediaintefun=function(LM){ #function creating Confidence Interval for Med
  CI.Med=matrix(NA,nrow=59,ncol=4)#Med:
  for (t in 1:59) {
    CI.Med[t,1]=LM$coefficients["factor(Ec)DEU"]+LM$coefficients["time"]*t#fitted values
    CI.Med[t,2]=1*vcov(LM)["factor(Ec)DEU","factor(Ec)DEU"]+t^2*vcov(LM)["time","time"]+
      2*1*t*vcov(LM)["factor(Ec)DEU","time"]#Variance
    CI.Med[t,3]=CI.Med[t,1]-qnorm(0.975)*sqrt(CI.Med[t,2])#95% CI lower
    CI.Med[t,4]=CI.Med[t,1]+qnorm(0.975)*sqrt(CI.Med[t,2])#95% CI upper
  }
  CI.Med=as.data.frame(CI.Med)
  CI.Med$t=c(1961:2019)
  CI.Med=CI.Med[43:53,]
  CI.Med
}
CI.LMMediafun80=function(LM,t0){ #function creating Confidence Interval for Med
  CI.Med=matrix(NA,nrow=29,ncol=4)#Med:
  for (t in 1:29) {
    t3=pmin(t,10+t0)
    t4=pmax(10+t0,pmin(t,20+t0))
    t5=pmax(20+t0,t)
    CI.Med[t,1]=LM$coefficients["factor(Ec)DEU"]+LM$coefficients["time3"]*t3+LM$coefficients["time4"]*t4+LM$coefficients["time5"]*t5#fitted values
    CI.Med[t,2]=1*vcov(LM)["factor(Ec)DEU","factor(Ec)DEU"]+t3^2*vcov(LM)["time3","time3"]+t4^2*vcov(LM)["time4","time4"]+t5^2*vcov(LM)["time5","time5"]+
      2*1*t3*vcov(LM)["factor(Ec)DEU","time3"]+2*1*t4*vcov(LM)["factor(Ec)DEU","time4"]+2*1*t5*vcov(LM)["factor(Ec)DEU","time5"]+
      2*t3*t4*vcov(LM)["time3","time4"]+2*t3*t5*vcov(LM)["time3","time5"]+
      2*t4*t5*vcov(LM)["time4","time5"]#Variance
    CI.Med[t,3]=CI.Med[t,1]-qnorm(0.975)*sqrt(CI.Med[t,2])#95% CI lower
    CI.Med[t,4]=CI.Med[t,1]+qnorm(0.975)*sqrt(CI.Med[t,2])#95% CI upper
  }
  CI.Med=as.data.frame(CI.Med)
  CI.Med$t=c(1981:2009)
  CI.Med
}
CI.LMMediafun80=function(LM,t0){ #function creating Confidence Interval for Med
  CI.Med=matrix(NA,nrow=29,ncol=4)#Med:
  for (t in 1:29) {
    t3=pmin(t,10+t0)
    t4=pmax(10+t0,pmin(t,20+t0))
    t5=pmax(20+t0,t)
    CI.Med[t,1]=LM$coefficients["time3"]*t3+LM$coefficients["time4"]*t4+LM$coefficients["time5"]*t5#fitted values
    CI.Med[t,2]=t3^2*vcov(LM)["time3","time3"]+t4^2*vcov(LM)["time4","time4"]+t5^2*vcov(LM)["time5","time5"]+
      2*t3*t4*vcov(LM)["time3","time4"]+2*t3*t5*vcov(LM)["time3","time5"]+
      2*t4*t5*vcov(LM)["time4","time5"]#Variance
    CI.Med[t,3]=CI.Med[t,1]-qnorm(0.975)*sqrt(CI.Med[t,2])#95% CI lower
    CI.Med[t,4]=CI.Med[t,1]+qnorm(0.975)*sqrt(CI.Med[t,2])#95% CI upper
  }
  CI.Med=as.data.frame(CI.Med)
  CI.Med$t=c(1981:2009)
  CI.Med
}

#time variables:
t0=0#starting value for thresholds (-4,-2,0,2,4)
de$time3=pmin(de$time,30+t0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=pmax(30+t0,pmin(de$time,40+t0))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=pmax(40+t0,de$time)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions all respondents:
LM_Mnwsp_0=lm_robust(Mnwsp ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
LM_Mradi_0=lm_robust(Mradi ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
LM_Mtele_0=lm_robust(Mtele ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
LM_Minte=lm_robust(Minte ~ time+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
L_Mnwsp_0=lm(Mnwsp ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
L_Mradi_0=lm(Mradi ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
L_Mtele_0=lm(Mtele ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
L_Minte=lm(Minte ~ time+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
sort(unique(de$Es[!is.na(de$Mtele)]))#Mtele from 42 election studies
```

```
## Error in de$Es: object of type 'closure' is not subsettable
```

``` r
##Figure 1##
#plots all respondents:
# tikz(paste0("plot_","LM_Mnwsp_0",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Newspaper") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMnwsp) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LM_Mnwsp_0,0)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMnwsp' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","LM_Mradi_0",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Radio") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMradi) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LM_Mradi_0,0)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMradi' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","LM_Mtele_0",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Television") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMtele) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LM_Mtele_0,0)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMtele' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","LM_Minte",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Internet") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMinte) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediaintefun(LM_Minte)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMinte' not found
```

``` r
# dev.off()


##MEDIA - USE OF MEDIA OVER TIME - ALTERNATIVE THRESHOLDS:----

##starting value for thresholds -4
#time variables:
t0=-4#starting value for thresholds (-4,-2,0,2,4)
de$time3=pmin(de$time,30+t0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=pmax(30+t0,pmin(de$time,40+t0))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=pmax(40+t0,de$time)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions all respondents:
LMn_m4=lm_robust(Mnwsp ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
LMr_m4=lm_robust(Mradi ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
LMt_m4=lm_robust(Mtele ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Ln_m4=lm(Mnwsp ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Lr_m4=lm(Mradi ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Lt_m4=lm(Mtele ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
#plots all respondents:
# tikz(paste0("plot_","LM_Mnwsp_m4",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Newspaper") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMnwsp) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMn_m4,-4)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMnwsp' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","LM_Mradi_m4",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Radio") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMradi) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMr_m4,-4)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMradi' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","LM_Mtele_m4",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Television") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMtele) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMt_m4,-4)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMtele' not found
```

``` r
# dev.off()


##starting value for thresholds -2
#time variables:
t0=-2#starting value for thresholds (-4,-2,0,2,4)
de$time3=pmin(de$time,30+t0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=pmax(30+t0,pmin(de$time,40+t0))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=pmax(40+t0,de$time)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions all respondents:
LMn_m2=lm_robust(Mnwsp ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
LMr_m2=lm_robust(Mradi ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
LMt_m2=lm_robust(Mtele ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Ln_m2=lm(Mnwsp ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Lr_m2=lm(Mradi ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Lt_m2=lm(Mtele ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
#plots all respondents:
# tikz(paste0("plot_","LM_Mnwsp_m2",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Newspaper") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMnwsp) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMn_m2,-2)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMnwsp' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","LM_Mradi_m2",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Radio") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMradi) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMr_m2,-2)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMradi' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","LM_Mtele_m2",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Television") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMtele) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMt_m2,-2)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMtele' not found
```

``` r
# dev.off()


##starting value for thresholds 2
#time variables:
t0=2#starting value for thresholds (-4,-2,0,2,4)
de$time3=pmin(de$time,30+t0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=pmax(30+t0,pmin(de$time,40+t0))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=pmax(40+t0,de$time)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions all respondents:
LMn_2=lm_robust(Mnwsp ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
LMr_2=lm_robust(Mradi ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
LMt_2=lm_robust(Mtele ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Ln_2=lm(Mnwsp ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Lr_2=lm(Mradi ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Lt_2=lm(Mtele ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
#plots all respondents:
# tikz(paste0("plot_","LM_Mnwsp_2",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Newspaper") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMnwsp) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMn_2,2)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMnwsp' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","LM_Mradi_2",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Radio") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMradi) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMr_2,2)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMradi' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","LM_Mtele_2",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Television") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMtele) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMt_2,2)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMtele' not found
```

``` r
# dev.off()


##starting value for thresholds 4
#time variables:
t0=4#starting value for thresholds (-4,-2,0,2,4)
de$time3=pmin(de$time,30+t0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=pmax(30+t0,pmin(de$time,40+t0))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=pmax(40+t0,de$time)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions all respondents:
LMn_4=lm_robust(Mnwsp ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
LMr_4=lm_robust(Mradi ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
LMt_4=lm_robust(Mtele ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Ln_4=lm(Mnwsp ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Lr_4=lm(Mradi ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Lt_4=lm(Mtele ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
#plots all respondents:
# tikz(paste0("plot_","LM_Mnwsp_4",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Newspaper") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMnwsp) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMn_4,4)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMnwsp' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","LM_Mradi_4",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Radio") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMradi) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMr_4,4)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMradi' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","LM_Mtele_4",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Television") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(0.0001,1)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(1-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyMtele) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMt_4,4)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyMtele' not found
```

``` r
# dev.off()


##table full results:
##Table D5##
stargazer(Ln_m4,Ln_m2,L_Mnwsp_0,Ln_2,Ln_4,#Mnwsp
          se = list(LMn_m4$std.error,LMn_m2$std.error,LM_Mnwsp_0$std.error,LMn_2$std.error,LMn_4$std.error))
```

```
## Error in eval(expr, envir, enclos): object 'Ln_m4' not found
```

``` r
##Table D6##
stargazer(Lr_m4,Lr_m2,L_Mradi_0,Lr_2,Lr_4,#Mradi
          se = list(LMr_m4$std.error,LMr_m2$std.error,LM_Mradi_0$std.error,LMr_2$std.error,LMr_4$std.error))
```

```
## Error in eval(expr, envir, enclos): object 'Lr_m4' not found
```

``` r
##Table D7##
stargazer(Lt_m4,Lt_m2,L_Mtele_0,Lt_2,Lt_4,#Mtele
          se = list(LMt_m4$std.error,LMt_m2$std.error,LM_Mtele_0$std.error,LMt_2$std.error,LMt_4$std.error))
```

```
## Error in eval(expr, envir, enclos): object 'Lt_m4' not found
```

``` r
#MEDIA - EFFECT OF LIKABILITY * MEDIA USE:----

#regressions with election-slope FE:

#prepare variables:
#Pl:Es FE:
for (i1 in 1:length(sort(unique(de$Es)))) {
  de[[paste0("Pl_",sort(unique(de$Es))[i1])]]=ifelse(de$Es==sort(unique(de$Es))[i1],de$Pl,0)
}
```

```
## Error in de$Es: object of type 'closure' is not subsettable
```

``` r
#Ll:Es FE:
for (i1 in 1:length(sort(unique(de$Es)))) {
  de[[paste0("Ll_",sort(unique(de$Es))[i1])]]=ifelse(de$Es==sort(unique(de$Es))[i1],de$Ll,0)
}
```

```
## Error in de$Es: object of type 'closure' is not subsettable
```

``` r
#regressions:
# (+Pl+Ll already in due to the country-slope FE)
# (Mnwsp alone cannot be estimated because it is a multinomial model and it is constant across choices)
CLC_nwsp_=clogit(Va ~ Pl:Mnwsp+Ll:Mnwsp
                 +Pl_AUS_1993+Ll_AUS_1993+Pl_AUS_1996+Ll_AUS_1996+Pl_AUS_1998+Ll_AUS_1998+Pl_AUS_2001+Ll_AUS_2001+Pl_AUS_2004+Ll_AUS_2004+Pl_AUS_2007+Ll_AUS_2007+Pl_AUS_2013+Ll_AUS_2013+Pl_AUS_2019+Ll_AUS_2019+Pl_AUT_2013+Ll_AUT_2013+Pl_AUT_2017+Ll_AUT_2017+Pl_CAN_1968+Ll_CAN_1968+Pl_CAN_1974+Ll_CAN_1974+Pl_CAN_1979+Ll_CAN_1979+Pl_CAN_1988+Ll_CAN_1988+Pl_CAN_1993+Ll_CAN_1993+Pl_CAN_1997+Ll_CAN_1997+Pl_CAN_2008+Ll_CAN_2008+Pl_CAN_2011+Ll_CAN_2011+Pl_CAN_2015+Ll_CAN_2015+Pl_DEU_1961+Ll_DEU_1961+Pl_DEU_1965+Ll_DEU_1965+Pl_DEU_1976+Ll_DEU_1976+Pl_DEU_1980+Ll_DEU_1980+Pl_DEU_1983+Ll_DEU_1983+Pl_DEU_1987+Ll_DEU_1987+Pl_DEU_1990+Ll_DEU_1990+Pl_DEU_1994+Ll_DEU_1994+Pl_DEU_1998+Ll_DEU_1998+Pl_DEU_2005+Ll_DEU_2005+Pl_DEU_2009+Ll_DEU_2009+Pl_DEU_2013+Ll_DEU_2013+Pl_DEU_2017+Ll_DEU_2017+Pl_DNK_1971+Ll_DNK_1971+Pl_DNK_1973+Ll_DNK_1973+Pl_DNK_1994+Ll_DNK_1994+Pl_DNK_1998+Ll_DNK_1998+Pl_DNK_2007+Ll_DNK_2007+Pl_ESP_1979+Ll_ESP_1979+Pl_ESP_1982+Ll_ESP_1982+Pl_ESP_1993+Ll_ESP_1993+Pl_ESP_1996+Ll_ESP_1996+Pl_ESP_2000+Ll_ESP_2000+Pl_ESP_2004+Ll_ESP_2004+Pl_ESP_2008+Ll_ESP_2008+Pl_FIN_2003+Ll_FIN_2003+Pl_FIN_2007+Ll_FIN_2007+Pl_FIN_2011+Ll_FIN_2011+Pl_FIN_2015+Ll_FIN_2015+Pl_GBR_1974f+Ll_GBR_1974f+Pl_GBR_1974o+Ll_GBR_1974o+Pl_GBR_1979+Ll_GBR_1979+Pl_GBR_1997+Ll_GBR_1997+Pl_GBR_2001+Ll_GBR_2001+Pl_GBR_2005+Ll_GBR_2005+Pl_GBR_2015+Ll_GBR_2015+Pl_GRC_1985+Ll_GRC_1985+Pl_GRC_1989+Ll_GRC_1989+Pl_GRC_1990+Ll_GRC_1990+Pl_GRC_1996+Ll_GRC_1996+Pl_GRC_2000+Ll_GRC_2000+Pl_GRC_2004+Ll_GRC_2004+Pl_GRC_2007+Ll_GRC_2007+Pl_GRC_2009+Ll_GRC_2009+Pl_GRC_2012+Ll_GRC_2012+Pl_GRC_2015j+Ll_GRC_2015j+Pl_GRC_2015s+Ll_GRC_2015s+Pl_IRL_2002+Ll_IRL_2002+Pl_IRL_2007+Ll_IRL_2007+Pl_IRL_2011+Ll_IRL_2011+Pl_IRL_2016+Ll_IRL_2016+Pl_ISL_1987+Ll_ISL_1987+Pl_ISL_1991+Ll_ISL_1991+Pl_ISL_1995+Ll_ISL_1995+Pl_ISL_1999+Ll_ISL_1999+Pl_ISL_2003+Ll_ISL_2003+Pl_ISL_2007+Ll_ISL_2007+Pl_ISL_2009+Ll_ISL_2009+Pl_ISL_2013+Ll_ISL_2013+Pl_ISL_2016+Ll_ISL_2016+Pl_ISL_2017+Ll_ISL_2017+Pl_ISR_1996+Ll_ISR_1996+Pl_ISR_2006+Ll_ISR_2006+Pl_ISR_2013+Ll_ISR_2013+Pl_ITA_2006+Ll_ITA_2006+Pl_ITA_2008+Ll_ITA_2008+Pl_ITA_2018+Ll_ITA_2018+Pl_NLD_1986+Ll_NLD_1986+Pl_NLD_1994+Ll_NLD_1994+Pl_NLD_1998+Ll_NLD_1998+Pl_NLD_2002+Ll_NLD_2002+Pl_NLD_2006+Ll_NLD_2006+Pl_NLD_2010+Ll_NLD_2010+Pl_NOR_1981+Ll_NOR_1981+Pl_NOR_1985+Ll_NOR_1985+Pl_NOR_1989+Ll_NOR_1989+Pl_NOR_1993+Ll_NOR_1993+Pl_NOR_1997+Ll_NOR_1997+Pl_NOR_2001+Ll_NOR_2001+Pl_NOR_2005+Ll_NOR_2005+Pl_NOR_2009+Ll_NOR_2009+Pl_NOR_2013+Ll_NOR_2013+Pl_NOR_2017+Ll_NOR_2017+Pl_NZL_1996+Ll_NZL_1996+Pl_NZL_2008+Ll_NZL_2008+Pl_NZL_2011+Ll_NZL_2011+Pl_NZL_2014+Ll_NZL_2014+Pl_NZL_2017+Ll_NZL_2017+Pl_PRT_2002+Ll_PRT_2002+Pl_PRT_2005+Ll_PRT_2005+Pl_PRT_2009+Ll_PRT_2009+Pl_PRT_2015+Ll_PRT_2015+Pl_SWE_1979+Ll_SWE_1979+Pl_SWE_1982+Ll_SWE_1982+Pl_SWE_1985+Ll_SWE_1985+Pl_SWE_1988+Ll_SWE_1988+Pl_SWE_1991+Ll_SWE_1991+Pl_SWE_1994+Ll_SWE_1994+Pl_SWE_1998+Ll_SWE_1998+Pl_SWE_2002+Ll_SWE_2002+Pl_SWE_2006+Ll_SWE_2006+Pl_SWE_2010+Ll_SWE_2010+Pl_SWE_2014+Ll_SWE_2014
                 +strata(Esalt), robust=T, data=de, method="efron")
```

```
## Error in model.frame.default(formula = Va ~ Pl:Mnwsp + Ll:Mnwsp + Pl_AUS_1993 + : 'data' must be a data.frame, environment, or list
```

``` r
CLC_radi_=clogit(Va ~ Pl:Mradi+Ll:Mradi
                 +Pl_AUS_1993+Ll_AUS_1993+Pl_AUS_1996+Ll_AUS_1996+Pl_AUS_1998+Ll_AUS_1998+Pl_AUS_2001+Ll_AUS_2001+Pl_AUS_2004+Ll_AUS_2004+Pl_AUS_2007+Ll_AUS_2007+Pl_AUS_2013+Ll_AUS_2013+Pl_AUS_2019+Ll_AUS_2019+Pl_AUT_2013+Ll_AUT_2013+Pl_AUT_2017+Ll_AUT_2017+Pl_CAN_1968+Ll_CAN_1968+Pl_CAN_1974+Ll_CAN_1974+Pl_CAN_1979+Ll_CAN_1979+Pl_CAN_1988+Ll_CAN_1988+Pl_CAN_1993+Ll_CAN_1993+Pl_CAN_1997+Ll_CAN_1997+Pl_CAN_2008+Ll_CAN_2008+Pl_CAN_2011+Ll_CAN_2011+Pl_CAN_2015+Ll_CAN_2015+Pl_DEU_1961+Ll_DEU_1961+Pl_DEU_1965+Ll_DEU_1965+Pl_DEU_1976+Ll_DEU_1976+Pl_DEU_1980+Ll_DEU_1980+Pl_DEU_1983+Ll_DEU_1983+Pl_DEU_1987+Ll_DEU_1987+Pl_DEU_1990+Ll_DEU_1990+Pl_DEU_1994+Ll_DEU_1994+Pl_DEU_1998+Ll_DEU_1998+Pl_DEU_2005+Ll_DEU_2005+Pl_DEU_2009+Ll_DEU_2009+Pl_DEU_2013+Ll_DEU_2013+Pl_DEU_2017+Ll_DEU_2017+Pl_DNK_1971+Ll_DNK_1971+Pl_DNK_1973+Ll_DNK_1973+Pl_DNK_1994+Ll_DNK_1994+Pl_DNK_1998+Ll_DNK_1998+Pl_DNK_2007+Ll_DNK_2007+Pl_ESP_1979+Ll_ESP_1979+Pl_ESP_1982+Ll_ESP_1982+Pl_ESP_1993+Ll_ESP_1993+Pl_ESP_1996+Ll_ESP_1996+Pl_ESP_2000+Ll_ESP_2000+Pl_ESP_2004+Ll_ESP_2004+Pl_ESP_2008+Ll_ESP_2008+Pl_FIN_2003+Ll_FIN_2003+Pl_FIN_2007+Ll_FIN_2007+Pl_FIN_2011+Ll_FIN_2011+Pl_FIN_2015+Ll_FIN_2015+Pl_GBR_1974f+Ll_GBR_1974f+Pl_GBR_1974o+Ll_GBR_1974o+Pl_GBR_1979+Ll_GBR_1979+Pl_GBR_1997+Ll_GBR_1997+Pl_GBR_2001+Ll_GBR_2001+Pl_GBR_2005+Ll_GBR_2005+Pl_GBR_2015+Ll_GBR_2015+Pl_GRC_1985+Ll_GRC_1985+Pl_GRC_1989+Ll_GRC_1989+Pl_GRC_1990+Ll_GRC_1990+Pl_GRC_1996+Ll_GRC_1996+Pl_GRC_2000+Ll_GRC_2000+Pl_GRC_2004+Ll_GRC_2004+Pl_GRC_2007+Ll_GRC_2007+Pl_GRC_2009+Ll_GRC_2009+Pl_GRC_2012+Ll_GRC_2012+Pl_GRC_2015j+Ll_GRC_2015j+Pl_GRC_2015s+Ll_GRC_2015s+Pl_IRL_2002+Ll_IRL_2002+Pl_IRL_2007+Ll_IRL_2007+Pl_IRL_2011+Ll_IRL_2011+Pl_IRL_2016+Ll_IRL_2016+Pl_ISL_1987+Ll_ISL_1987+Pl_ISL_1991+Ll_ISL_1991+Pl_ISL_1995+Ll_ISL_1995+Pl_ISL_1999+Ll_ISL_1999+Pl_ISL_2003+Ll_ISL_2003+Pl_ISL_2007+Ll_ISL_2007+Pl_ISL_2009+Ll_ISL_2009+Pl_ISL_2013+Ll_ISL_2013+Pl_ISL_2016+Ll_ISL_2016+Pl_ISL_2017+Ll_ISL_2017+Pl_ISR_1996+Ll_ISR_1996+Pl_ISR_2006+Ll_ISR_2006+Pl_ISR_2013+Ll_ISR_2013+Pl_ITA_2006+Ll_ITA_2006+Pl_ITA_2008+Ll_ITA_2008+Pl_ITA_2018+Ll_ITA_2018+Pl_NLD_1986+Ll_NLD_1986+Pl_NLD_1994+Ll_NLD_1994+Pl_NLD_1998+Ll_NLD_1998+Pl_NLD_2002+Ll_NLD_2002+Pl_NLD_2006+Ll_NLD_2006+Pl_NLD_2010+Ll_NLD_2010+Pl_NOR_1981+Ll_NOR_1981+Pl_NOR_1985+Ll_NOR_1985+Pl_NOR_1989+Ll_NOR_1989+Pl_NOR_1993+Ll_NOR_1993+Pl_NOR_1997+Ll_NOR_1997+Pl_NOR_2001+Ll_NOR_2001+Pl_NOR_2005+Ll_NOR_2005+Pl_NOR_2009+Ll_NOR_2009+Pl_NOR_2013+Ll_NOR_2013+Pl_NOR_2017+Ll_NOR_2017+Pl_NZL_1996+Ll_NZL_1996+Pl_NZL_2008+Ll_NZL_2008+Pl_NZL_2011+Ll_NZL_2011+Pl_NZL_2014+Ll_NZL_2014+Pl_NZL_2017+Ll_NZL_2017+Pl_PRT_2002+Ll_PRT_2002+Pl_PRT_2005+Ll_PRT_2005+Pl_PRT_2009+Ll_PRT_2009+Pl_PRT_2015+Ll_PRT_2015+Pl_SWE_1979+Ll_SWE_1979+Pl_SWE_1982+Ll_SWE_1982+Pl_SWE_1985+Ll_SWE_1985+Pl_SWE_1988+Ll_SWE_1988+Pl_SWE_1991+Ll_SWE_1991+Pl_SWE_1994+Ll_SWE_1994+Pl_SWE_1998+Ll_SWE_1998+Pl_SWE_2002+Ll_SWE_2002+Pl_SWE_2006+Ll_SWE_2006+Pl_SWE_2010+Ll_SWE_2010+Pl_SWE_2014+Ll_SWE_2014
                 +strata(Esalt), robust=T, data=de, method="efron")
```

```
## Error in model.frame.default(formula = Va ~ Pl:Mradi + Ll:Mradi + Pl_AUS_1993 + : 'data' must be a data.frame, environment, or list
```

``` r
CLC_tele_=clogit(Va ~ Pl:Mtele+Ll:Mtele
                 +Pl_AUS_1993+Ll_AUS_1993+Pl_AUS_1996+Ll_AUS_1996+Pl_AUS_1998+Ll_AUS_1998+Pl_AUS_2001+Ll_AUS_2001+Pl_AUS_2004+Ll_AUS_2004+Pl_AUS_2007+Ll_AUS_2007+Pl_AUS_2013+Ll_AUS_2013+Pl_AUS_2019+Ll_AUS_2019+Pl_AUT_2013+Ll_AUT_2013+Pl_AUT_2017+Ll_AUT_2017+Pl_CAN_1968+Ll_CAN_1968+Pl_CAN_1974+Ll_CAN_1974+Pl_CAN_1979+Ll_CAN_1979+Pl_CAN_1988+Ll_CAN_1988+Pl_CAN_1993+Ll_CAN_1993+Pl_CAN_1997+Ll_CAN_1997+Pl_CAN_2008+Ll_CAN_2008+Pl_CAN_2011+Ll_CAN_2011+Pl_CAN_2015+Ll_CAN_2015+Pl_DEU_1961+Ll_DEU_1961+Pl_DEU_1965+Ll_DEU_1965+Pl_DEU_1976+Ll_DEU_1976+Pl_DEU_1980+Ll_DEU_1980+Pl_DEU_1983+Ll_DEU_1983+Pl_DEU_1987+Ll_DEU_1987+Pl_DEU_1990+Ll_DEU_1990+Pl_DEU_1994+Ll_DEU_1994+Pl_DEU_1998+Ll_DEU_1998+Pl_DEU_2005+Ll_DEU_2005+Pl_DEU_2009+Ll_DEU_2009+Pl_DEU_2013+Ll_DEU_2013+Pl_DEU_2017+Ll_DEU_2017+Pl_DNK_1971+Ll_DNK_1971+Pl_DNK_1973+Ll_DNK_1973+Pl_DNK_1994+Ll_DNK_1994+Pl_DNK_1998+Ll_DNK_1998+Pl_DNK_2007+Ll_DNK_2007+Pl_ESP_1979+Ll_ESP_1979+Pl_ESP_1982+Ll_ESP_1982+Pl_ESP_1993+Ll_ESP_1993+Pl_ESP_1996+Ll_ESP_1996+Pl_ESP_2000+Ll_ESP_2000+Pl_ESP_2004+Ll_ESP_2004+Pl_ESP_2008+Ll_ESP_2008+Pl_FIN_2003+Ll_FIN_2003+Pl_FIN_2007+Ll_FIN_2007+Pl_FIN_2011+Ll_FIN_2011+Pl_FIN_2015+Ll_FIN_2015+Pl_GBR_1974f+Ll_GBR_1974f+Pl_GBR_1974o+Ll_GBR_1974o+Pl_GBR_1979+Ll_GBR_1979+Pl_GBR_1997+Ll_GBR_1997+Pl_GBR_2001+Ll_GBR_2001+Pl_GBR_2005+Ll_GBR_2005+Pl_GBR_2015+Ll_GBR_2015+Pl_GRC_1985+Ll_GRC_1985+Pl_GRC_1989+Ll_GRC_1989+Pl_GRC_1990+Ll_GRC_1990+Pl_GRC_1996+Ll_GRC_1996+Pl_GRC_2000+Ll_GRC_2000+Pl_GRC_2004+Ll_GRC_2004+Pl_GRC_2007+Ll_GRC_2007+Pl_GRC_2009+Ll_GRC_2009+Pl_GRC_2012+Ll_GRC_2012+Pl_GRC_2015j+Ll_GRC_2015j+Pl_GRC_2015s+Ll_GRC_2015s+Pl_IRL_2002+Ll_IRL_2002+Pl_IRL_2007+Ll_IRL_2007+Pl_IRL_2011+Ll_IRL_2011+Pl_IRL_2016+Ll_IRL_2016+Pl_ISL_1987+Ll_ISL_1987+Pl_ISL_1991+Ll_ISL_1991+Pl_ISL_1995+Ll_ISL_1995+Pl_ISL_1999+Ll_ISL_1999+Pl_ISL_2003+Ll_ISL_2003+Pl_ISL_2007+Ll_ISL_2007+Pl_ISL_2009+Ll_ISL_2009+Pl_ISL_2013+Ll_ISL_2013+Pl_ISL_2016+Ll_ISL_2016+Pl_ISL_2017+Ll_ISL_2017+Pl_ISR_1996+Ll_ISR_1996+Pl_ISR_2006+Ll_ISR_2006+Pl_ISR_2013+Ll_ISR_2013+Pl_ITA_2006+Ll_ITA_2006+Pl_ITA_2008+Ll_ITA_2008+Pl_ITA_2018+Ll_ITA_2018+Pl_NLD_1986+Ll_NLD_1986+Pl_NLD_1994+Ll_NLD_1994+Pl_NLD_1998+Ll_NLD_1998+Pl_NLD_2002+Ll_NLD_2002+Pl_NLD_2006+Ll_NLD_2006+Pl_NLD_2010+Ll_NLD_2010+Pl_NOR_1981+Ll_NOR_1981+Pl_NOR_1985+Ll_NOR_1985+Pl_NOR_1989+Ll_NOR_1989+Pl_NOR_1993+Ll_NOR_1993+Pl_NOR_1997+Ll_NOR_1997+Pl_NOR_2001+Ll_NOR_2001+Pl_NOR_2005+Ll_NOR_2005+Pl_NOR_2009+Ll_NOR_2009+Pl_NOR_2013+Ll_NOR_2013+Pl_NOR_2017+Ll_NOR_2017+Pl_NZL_1996+Ll_NZL_1996+Pl_NZL_2008+Ll_NZL_2008+Pl_NZL_2011+Ll_NZL_2011+Pl_NZL_2014+Ll_NZL_2014+Pl_NZL_2017+Ll_NZL_2017+Pl_PRT_2002+Ll_PRT_2002+Pl_PRT_2005+Ll_PRT_2005+Pl_PRT_2009+Ll_PRT_2009+Pl_PRT_2015+Ll_PRT_2015+Pl_SWE_1979+Ll_SWE_1979+Pl_SWE_1982+Ll_SWE_1982+Pl_SWE_1985+Ll_SWE_1985+Pl_SWE_1988+Ll_SWE_1988+Pl_SWE_1991+Ll_SWE_1991+Pl_SWE_1994+Ll_SWE_1994+Pl_SWE_1998+Ll_SWE_1998+Pl_SWE_2002+Ll_SWE_2002+Pl_SWE_2006+Ll_SWE_2006+Pl_SWE_2010+Ll_SWE_2010+Pl_SWE_2014+Ll_SWE_2014
                 +strata(Esalt), robust=T, data=de, method="efron")
```

```
## Error in model.frame.default(formula = Va ~ Pl:Mtele + Ll:Mtele + Pl_AUS_1993 + : 'data' must be a data.frame, environment, or list
```

``` r
CLC_inte_=clogit(Va ~ Pl:Minte+Ll:Minte
                 +Pl_AUS_1993+Ll_AUS_1993+Pl_AUS_1996+Ll_AUS_1996+Pl_AUS_1998+Ll_AUS_1998+Pl_AUS_2001+Ll_AUS_2001+Pl_AUS_2004+Ll_AUS_2004+Pl_AUS_2007+Ll_AUS_2007+Pl_AUS_2013+Ll_AUS_2013+Pl_AUS_2019+Ll_AUS_2019+Pl_AUT_2013+Ll_AUT_2013+Pl_AUT_2017+Ll_AUT_2017+Pl_CAN_1968+Ll_CAN_1968+Pl_CAN_1974+Ll_CAN_1974+Pl_CAN_1979+Ll_CAN_1979+Pl_CAN_1988+Ll_CAN_1988+Pl_CAN_1993+Ll_CAN_1993+Pl_CAN_1997+Ll_CAN_1997+Pl_CAN_2008+Ll_CAN_2008+Pl_CAN_2011+Ll_CAN_2011+Pl_CAN_2015+Ll_CAN_2015+Pl_DEU_1961+Ll_DEU_1961+Pl_DEU_1965+Ll_DEU_1965+Pl_DEU_1976+Ll_DEU_1976+Pl_DEU_1980+Ll_DEU_1980+Pl_DEU_1983+Ll_DEU_1983+Pl_DEU_1987+Ll_DEU_1987+Pl_DEU_1990+Ll_DEU_1990+Pl_DEU_1994+Ll_DEU_1994+Pl_DEU_1998+Ll_DEU_1998+Pl_DEU_2005+Ll_DEU_2005+Pl_DEU_2009+Ll_DEU_2009+Pl_DEU_2013+Ll_DEU_2013+Pl_DEU_2017+Ll_DEU_2017+Pl_DNK_1971+Ll_DNK_1971+Pl_DNK_1973+Ll_DNK_1973+Pl_DNK_1994+Ll_DNK_1994+Pl_DNK_1998+Ll_DNK_1998+Pl_DNK_2007+Ll_DNK_2007+Pl_ESP_1979+Ll_ESP_1979+Pl_ESP_1982+Ll_ESP_1982+Pl_ESP_1993+Ll_ESP_1993+Pl_ESP_1996+Ll_ESP_1996+Pl_ESP_2000+Ll_ESP_2000+Pl_ESP_2004+Ll_ESP_2004+Pl_ESP_2008+Ll_ESP_2008+Pl_FIN_2003+Ll_FIN_2003+Pl_FIN_2007+Ll_FIN_2007+Pl_FIN_2011+Ll_FIN_2011+Pl_FIN_2015+Ll_FIN_2015+Pl_GBR_1974f+Ll_GBR_1974f+Pl_GBR_1974o+Ll_GBR_1974o+Pl_GBR_1979+Ll_GBR_1979+Pl_GBR_1997+Ll_GBR_1997+Pl_GBR_2001+Ll_GBR_2001+Pl_GBR_2005+Ll_GBR_2005+Pl_GBR_2015+Ll_GBR_2015+Pl_GRC_1985+Ll_GRC_1985+Pl_GRC_1989+Ll_GRC_1989+Pl_GRC_1990+Ll_GRC_1990+Pl_GRC_1996+Ll_GRC_1996+Pl_GRC_2000+Ll_GRC_2000+Pl_GRC_2004+Ll_GRC_2004+Pl_GRC_2007+Ll_GRC_2007+Pl_GRC_2009+Ll_GRC_2009+Pl_GRC_2012+Ll_GRC_2012+Pl_GRC_2015j+Ll_GRC_2015j+Pl_GRC_2015s+Ll_GRC_2015s+Pl_IRL_2002+Ll_IRL_2002+Pl_IRL_2007+Ll_IRL_2007+Pl_IRL_2011+Ll_IRL_2011+Pl_IRL_2016+Ll_IRL_2016+Pl_ISL_1987+Ll_ISL_1987+Pl_ISL_1991+Ll_ISL_1991+Pl_ISL_1995+Ll_ISL_1995+Pl_ISL_1999+Ll_ISL_1999+Pl_ISL_2003+Ll_ISL_2003+Pl_ISL_2007+Ll_ISL_2007+Pl_ISL_2009+Ll_ISL_2009+Pl_ISL_2013+Ll_ISL_2013+Pl_ISL_2016+Ll_ISL_2016+Pl_ISL_2017+Ll_ISL_2017+Pl_ISR_1996+Ll_ISR_1996+Pl_ISR_2006+Ll_ISR_2006+Pl_ISR_2013+Ll_ISR_2013+Pl_ITA_2006+Ll_ITA_2006+Pl_ITA_2008+Ll_ITA_2008+Pl_ITA_2018+Ll_ITA_2018+Pl_NLD_1986+Ll_NLD_1986+Pl_NLD_1994+Ll_NLD_1994+Pl_NLD_1998+Ll_NLD_1998+Pl_NLD_2002+Ll_NLD_2002+Pl_NLD_2006+Ll_NLD_2006+Pl_NLD_2010+Ll_NLD_2010+Pl_NOR_1981+Ll_NOR_1981+Pl_NOR_1985+Ll_NOR_1985+Pl_NOR_1989+Ll_NOR_1989+Pl_NOR_1993+Ll_NOR_1993+Pl_NOR_1997+Ll_NOR_1997+Pl_NOR_2001+Ll_NOR_2001+Pl_NOR_2005+Ll_NOR_2005+Pl_NOR_2009+Ll_NOR_2009+Pl_NOR_2013+Ll_NOR_2013+Pl_NOR_2017+Ll_NOR_2017+Pl_NZL_1996+Ll_NZL_1996+Pl_NZL_2008+Ll_NZL_2008+Pl_NZL_2011+Ll_NZL_2011+Pl_NZL_2014+Ll_NZL_2014+Pl_NZL_2017+Ll_NZL_2017+Pl_PRT_2002+Ll_PRT_2002+Pl_PRT_2005+Ll_PRT_2005+Pl_PRT_2009+Ll_PRT_2009+Pl_PRT_2015+Ll_PRT_2015+Pl_SWE_1979+Ll_SWE_1979+Pl_SWE_1982+Ll_SWE_1982+Pl_SWE_1985+Ll_SWE_1985+Pl_SWE_1988+Ll_SWE_1988+Pl_SWE_1991+Ll_SWE_1991+Pl_SWE_1994+Ll_SWE_1994+Pl_SWE_1998+Ll_SWE_1998+Pl_SWE_2002+Ll_SWE_2002+Pl_SWE_2006+Ll_SWE_2006+Pl_SWE_2010+Ll_SWE_2010+Pl_SWE_2014+Ll_SWE_2014
                 +strata(Esalt), robust=T, data=de, method="efron")
```

```
## Error in model.frame.default(formula = Va ~ Pl:Minte + Ll:Minte + Pl_AUS_1993 + : 'data' must be a data.frame, environment, or list
```

``` r
#change names for stargazer:
names(CLC_nwsp_$coefficients)[names(CLC_nwsp_$coefficients)=="Pl:Mnwsp"]="Party Likability * Media Use"
```

```
## Error: object 'CLC_nwsp_' not found
```

``` r
names(CLC_nwsp_$coefficients)[names(CLC_nwsp_$coefficients)=="Mnwsp:Ll"]="Leader Likability * Media Use"
```

```
## Error: object 'CLC_nwsp_' not found
```

``` r
names(CLC_radi_$coefficients)[names(CLC_radi_$coefficients)=="Pl:Mradi"]="Party Likability * Media Use"
```

```
## Error: object 'CLC_radi_' not found
```

``` r
names(CLC_radi_$coefficients)[names(CLC_radi_$coefficients)=="Mradi:Ll"]="Leader Likability * Media Use"
```

```
## Error: object 'CLC_radi_' not found
```

``` r
names(CLC_tele_$coefficients)[names(CLC_tele_$coefficients)=="Pl:Mtele"]="Party Likability * Media Use"
```

```
## Error: object 'CLC_tele_' not found
```

``` r
names(CLC_tele_$coefficients)[names(CLC_tele_$coefficients)=="Mtele:Ll"]="Leader Likability * Media Use"
```

```
## Error: object 'CLC_tele_' not found
```

``` r
names(CLC_inte_$coefficients)[names(CLC_inte_$coefficients)=="Pl:Minte"]="Party Likability * Media Use"
```

```
## Error: object 'CLC_inte_' not found
```

``` r
names(CLC_inte_$coefficients)[names(CLC_inte_$coefficients)=="Minte:Ll"]="Leader Likability * Media Use"
```

```
## Error: object 'CLC_inte_' not found
```

``` r
##Table 3##
stargazer(CLC_nwsp_,CLC_radi_,CLC_tele_,CLC_inte_)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_nwsp_' not found
```

``` r
##MEDIA - RC MEASURING MTELE-MNWSP:----

#confidence interval functions:
CI.LMMediafun=function(LM,t0){ #function creating Confidence Interval for Med
  CI.Med=matrix(NA,nrow=59,ncol=4)#Med:
  for (t in 1:59) {
    t3=pmin(t,30+t0)
    t4=pmax(30+t0,pmin(t,40+t0))
    t5=pmax(40+t0,t)
    CI.Med[t,1]=LM$coefficients["factor(Ec)DEU"]+LM$coefficients["time3"]*t3+LM$coefficients["time4"]*t4+LM$coefficients["time5"]*t5#fitted values
    CI.Med[t,2]=1*vcov(LM)["factor(Ec)DEU","factor(Ec)DEU"]+t3^2*vcov(LM)["time3","time3"]+t4^2*vcov(LM)["time4","time4"]+t5^2*vcov(LM)["time5","time5"]+
      2*1*t3*vcov(LM)["factor(Ec)DEU","time3"]+2*1*t4*vcov(LM)["factor(Ec)DEU","time4"]+2*1*t5*vcov(LM)["factor(Ec)DEU","time5"]+
      2*t3*t4*vcov(LM)["time3","time4"]+2*t3*t5*vcov(LM)["time3","time5"]+
      2*t4*t5*vcov(LM)["time4","time5"]#Variance
    CI.Med[t,3]=CI.Med[t,1]-qnorm(0.975)*sqrt(CI.Med[t,2])#95% CI lower
    CI.Med[t,4]=CI.Med[t,1]+qnorm(0.975)*sqrt(CI.Med[t,2])#95% CI upper
  }
  CI.Med=as.data.frame(CI.Med)
  CI.Med$t=c(1961:2019)
  CI.Med=CI.Med[19:53,]
  CI.Med
}

#create variable Mtele-Mnwsp:
de$Mtesp=de$Mtele-de$Mnwsp
```

```
## Error in de$Mtele: object of type 'closure' is not subsettable
```

``` r
#time variables:
t0=0#starting value for thresholds (-4,-2,0,2,4)
de$time3=pmin(de$time,30+t0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=pmax(30+t0,pmin(de$time,40+t0))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=pmax(40+t0,de$time)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions all respondents:
LM_Mtesp_0=lm_robust(Mtesp ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
L_Mtesp_0=lm(Mtesp ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
##Figure 2##
#plots all respondents:
# tikz(paste0("plot_","LM_Mtesp_0",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Television $-$ Newspaper") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(-0.4999,0.5)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        # geom_histogram(aes(x=Ey,y=..density..),binwidth = 1,color="gray85",fill="gray85",data=de[!is.na(de$Mtesp),]) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LM_Mtesp_0,0)) )
```

```
## Error in eval(expr, envir, enclos): object 'LM_Mtesp_0' not found
```

``` r
# dev.off()


##table (regressions with election-slope FE):

#prepare variables:
#Pl:Es FE:
for (i1 in 1:length(sort(unique(de$Es)))) {
  de[[paste0("Pl_",sort(unique(de$Es))[i1])]]=ifelse(de$Es==sort(unique(de$Es))[i1],de$Pl,0)
}
```

```
## Error in de$Es: object of type 'closure' is not subsettable
```

``` r
#Ll:Es FE:
for (i1 in 1:length(sort(unique(de$Es)))) {
  de[[paste0("Ll_",sort(unique(de$Es))[i1])]]=ifelse(de$Es==sort(unique(de$Es))[i1],de$Ll,0)
}
```

```
## Error in de$Es: object of type 'closure' is not subsettable
```

``` r
#regressions:
CLC_tesp_=clogit(Va ~ Pl:Mtesp+Ll:Mtesp
                 +Pl_AUS_1993+Ll_AUS_1993+Pl_AUS_1996+Ll_AUS_1996+Pl_AUS_1998+Ll_AUS_1998+Pl_AUS_2001+Ll_AUS_2001+Pl_AUS_2004+Ll_AUS_2004+Pl_AUS_2007+Ll_AUS_2007+Pl_AUS_2013+Ll_AUS_2013+Pl_AUS_2019+Ll_AUS_2019+Pl_AUT_2013+Ll_AUT_2013+Pl_AUT_2017+Ll_AUT_2017+Pl_CAN_1968+Ll_CAN_1968+Pl_CAN_1974+Ll_CAN_1974+Pl_CAN_1979+Ll_CAN_1979+Pl_CAN_1988+Ll_CAN_1988+Pl_CAN_1993+Ll_CAN_1993+Pl_CAN_1997+Ll_CAN_1997+Pl_CAN_2008+Ll_CAN_2008+Pl_CAN_2011+Ll_CAN_2011+Pl_CAN_2015+Ll_CAN_2015+Pl_DEU_1961+Ll_DEU_1961+Pl_DEU_1965+Ll_DEU_1965+Pl_DEU_1976+Ll_DEU_1976+Pl_DEU_1980+Ll_DEU_1980+Pl_DEU_1983+Ll_DEU_1983+Pl_DEU_1987+Ll_DEU_1987+Pl_DEU_1990+Ll_DEU_1990+Pl_DEU_1994+Ll_DEU_1994+Pl_DEU_1998+Ll_DEU_1998+Pl_DEU_2005+Ll_DEU_2005+Pl_DEU_2009+Ll_DEU_2009+Pl_DEU_2013+Ll_DEU_2013+Pl_DEU_2017+Ll_DEU_2017+Pl_DNK_1971+Ll_DNK_1971+Pl_DNK_1973+Ll_DNK_1973+Pl_DNK_1994+Ll_DNK_1994+Pl_DNK_1998+Ll_DNK_1998+Pl_DNK_2007+Ll_DNK_2007+Pl_ESP_1979+Ll_ESP_1979+Pl_ESP_1982+Ll_ESP_1982+Pl_ESP_1993+Ll_ESP_1993+Pl_ESP_1996+Ll_ESP_1996+Pl_ESP_2000+Ll_ESP_2000+Pl_ESP_2004+Ll_ESP_2004+Pl_ESP_2008+Ll_ESP_2008+Pl_FIN_2003+Ll_FIN_2003+Pl_FIN_2007+Ll_FIN_2007+Pl_FIN_2011+Ll_FIN_2011+Pl_FIN_2015+Ll_FIN_2015+Pl_GBR_1974f+Ll_GBR_1974f+Pl_GBR_1974o+Ll_GBR_1974o+Pl_GBR_1979+Ll_GBR_1979+Pl_GBR_1997+Ll_GBR_1997+Pl_GBR_2001+Ll_GBR_2001+Pl_GBR_2005+Ll_GBR_2005+Pl_GBR_2015+Ll_GBR_2015+Pl_GRC_1985+Ll_GRC_1985+Pl_GRC_1989+Ll_GRC_1989+Pl_GRC_1990+Ll_GRC_1990+Pl_GRC_1996+Ll_GRC_1996+Pl_GRC_2000+Ll_GRC_2000+Pl_GRC_2004+Ll_GRC_2004+Pl_GRC_2007+Ll_GRC_2007+Pl_GRC_2009+Ll_GRC_2009+Pl_GRC_2012+Ll_GRC_2012+Pl_GRC_2015j+Ll_GRC_2015j+Pl_GRC_2015s+Ll_GRC_2015s+Pl_IRL_2002+Ll_IRL_2002+Pl_IRL_2007+Ll_IRL_2007+Pl_IRL_2011+Ll_IRL_2011+Pl_IRL_2016+Ll_IRL_2016+Pl_ISL_1987+Ll_ISL_1987+Pl_ISL_1991+Ll_ISL_1991+Pl_ISL_1995+Ll_ISL_1995+Pl_ISL_1999+Ll_ISL_1999+Pl_ISL_2003+Ll_ISL_2003+Pl_ISL_2007+Ll_ISL_2007+Pl_ISL_2009+Ll_ISL_2009+Pl_ISL_2013+Ll_ISL_2013+Pl_ISL_2016+Ll_ISL_2016+Pl_ISL_2017+Ll_ISL_2017+Pl_ISR_1996+Ll_ISR_1996+Pl_ISR_2006+Ll_ISR_2006+Pl_ISR_2013+Ll_ISR_2013+Pl_ITA_2006+Ll_ITA_2006+Pl_ITA_2008+Ll_ITA_2008+Pl_ITA_2018+Ll_ITA_2018+Pl_NLD_1986+Ll_NLD_1986+Pl_NLD_1994+Ll_NLD_1994+Pl_NLD_1998+Ll_NLD_1998+Pl_NLD_2002+Ll_NLD_2002+Pl_NLD_2006+Ll_NLD_2006+Pl_NLD_2010+Ll_NLD_2010+Pl_NOR_1981+Ll_NOR_1981+Pl_NOR_1985+Ll_NOR_1985+Pl_NOR_1989+Ll_NOR_1989+Pl_NOR_1993+Ll_NOR_1993+Pl_NOR_1997+Ll_NOR_1997+Pl_NOR_2001+Ll_NOR_2001+Pl_NOR_2005+Ll_NOR_2005+Pl_NOR_2009+Ll_NOR_2009+Pl_NOR_2013+Ll_NOR_2013+Pl_NOR_2017+Ll_NOR_2017+Pl_NZL_1996+Ll_NZL_1996+Pl_NZL_2008+Ll_NZL_2008+Pl_NZL_2011+Ll_NZL_2011+Pl_NZL_2014+Ll_NZL_2014+Pl_NZL_2017+Ll_NZL_2017+Pl_PRT_2002+Ll_PRT_2002+Pl_PRT_2005+Ll_PRT_2005+Pl_PRT_2009+Ll_PRT_2009+Pl_PRT_2015+Ll_PRT_2015+Pl_SWE_1979+Ll_SWE_1979+Pl_SWE_1982+Ll_SWE_1982+Pl_SWE_1985+Ll_SWE_1985+Pl_SWE_1988+Ll_SWE_1988+Pl_SWE_1991+Ll_SWE_1991+Pl_SWE_1994+Ll_SWE_1994+Pl_SWE_1998+Ll_SWE_1998+Pl_SWE_2002+Ll_SWE_2002+Pl_SWE_2006+Ll_SWE_2006+Pl_SWE_2010+Ll_SWE_2010+Pl_SWE_2014+Ll_SWE_2014
                 +strata(Esalt), robust=T, data=de, weights=Rwc, method="efron")
```

```
## Error in model.frame.default(formula = Va ~ Pl:Mtesp + Ll:Mtesp + Pl_AUS_1993 + : 'data' must be a data.frame, environment, or list
```

``` r
#change names for stargazer:
names(CLC_tesp_$coefficients)[names(CLC_tesp_$coefficients)=="Pl:Mtesp"]="Party Likability * Media Use"
```

```
## Error: object 'CLC_tesp_' not found
```

``` r
names(CLC_tesp_$coefficients)[names(CLC_tesp_$coefficients)=="Mtesp:Ll"]="Leader Likability * Media Use"
```

```
## Error: object 'CLC_tesp_' not found
```

``` r
##Table 4##
stargazer(CLC_tesp_)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_tesp_' not found
```

``` r
##MEDIA - RC MEASURING MTELE-MNWSP - ALTERNATIVE THRESHOLDS:----

##starting value for thresholds -4
#time variables:
t0=-4#starting value for thresholds (-4,-2,0,2,4)
de$time3=pmin(de$time,30+t0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=pmax(30+t0,pmin(de$time,40+t0))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=pmax(40+t0,de$time)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions all respondents:
LMm_m4=lm_robust(Mtesp ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Lm_m4=lm(Mtesp ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
#plots all respondents:
# tikz(paste0("plot_","LMm_m4",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Television $-$ Newspaper") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(-0.4999,0.5)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        # geom_histogram(aes(x=Ey,y=..density..),binwidth = 1,color="gray85",fill="gray85",data=de[!is.na(de$Mtesp),]) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMm_m4,-4)) )
```

```
## Error in eval(expr, envir, enclos): object 'LMm_m4' not found
```

``` r
# dev.off()


##starting value for thresholds -2
#time variables:
t0=-2#starting value for thresholds (-4,-2,0,2,4)
de$time3=pmin(de$time,30+t0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=pmax(30+t0,pmin(de$time,40+t0))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=pmax(40+t0,de$time)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions all respondents:
LMm_m2=lm_robust(Mtesp ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Lm_m2=lm(Mtesp ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
#plots all respondents:
# tikz(paste0("plot_","LMm_m2",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Television $-$ Newspaper") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(-0.4999,0.5)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        # geom_histogram(aes(x=Ey,y=..density..),binwidth = 1,color="gray85",fill="gray85",data=de[!is.na(de$Mtesp),]) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMm_m2,-2)) )
```

```
## Error in eval(expr, envir, enclos): object 'LMm_m2' not found
```

``` r
# dev.off()


##starting value for thresholds 2
#time variables:
t0=2#starting value for thresholds (-4,-2,0,2,4)
de$time3=pmin(de$time,30+t0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=pmax(30+t0,pmin(de$time,40+t0))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=pmax(40+t0,de$time)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions all respondents:
LMm_2=lm_robust(Mtesp ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Lm_2=lm(Mtesp ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
#plots all respondents:
# tikz(paste0("plot_","LMm_2",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Television $-$ Newspaper") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(-0.4999,0.5)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        # geom_histogram(aes(x=Ey,y=..density..),binwidth = 1,color="gray85",fill="gray85",data=de[!is.na(de$Mtesp),]) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMm_2,2)) )
```

```
## Error in eval(expr, envir, enclos): object 'LMm_2' not found
```

``` r
# dev.off()


##starting value for thresholds 4
#time variables:
t0=4#starting value for thresholds (-4,-2,0,2,4)
de$time3=pmin(de$time,30+t0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=pmax(30+t0,pmin(de$time,40+t0))
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=pmax(40+t0,de$time)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions all respondents:
LMm_4=lm_robust(Mtesp ~ time3+time4+time5+factor(Ec)-1, cluster=Ec, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
Lm_4=lm(Mtesp ~ time3+time4+time5+factor(Ec)-1, data=de[de$Ey>=1979,], se_type="stata")#regression
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
#plots all respondents:
# tikz(paste0("plot_","LMm_4",".tex"),width=4, height=3)#plot Ll:
plot( ggplot() 
      +ggtitle("Television $-$ Newspaper") 
      +xlab("Year") +ylab("Frequency Use") + coord_cartesian(ylim=c(-0.4999,0.5)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        # geom_histogram(aes(x=Ey,y=..density..),binwidth = 1,color="gray85",fill="gray85",data=de[!is.na(de$Mtesp),]) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.LMMediafun(LMm_4,4)) )
```

```
## Error in eval(expr, envir, enclos): object 'LMm_4' not found
```

``` r
# dev.off()


##Table D8##
##table full results:
stargazer(Lm_m4,Lm_m2,L_Mtesp_0,Lm_2,Lm_4,
          se = list(LMm_m4$std.error,LMm_m2$std.error,LM_Mtesp_0$std.error,LMm_2$std.error,LMm_4$std.error))
```

```
## Error in eval(expr, envir, enclos): object 'Lm_m4' not found
```

``` r
###MEDIA - EFFECT OF MEDIA USE ON LIKABILITY:----

##PlV-PlnV:
dt1=de %>% filter(Va==F) %>% group_by(chid) %>% mutate(PlnV=mean(Pl,na.rm=T))#avg Pl non-choices
```

```
## Error in UseMethod("filter"): no applicable method for 'filter' applied to an object of class "function"
```

``` r
dt1=dt1 %>% group_by(chid) %>% filter(row_number() == 1)#keep only one obs per respondent
```

```
## Error in eval(expr, envir, enclos): object 'dt1' not found
```

``` r
dt2=de %>% filter(Va==T) %>% group_by(chid) %>% mutate(PlV=mean(Pl,na.rm=T))#Pl choices
```

```
## Error in UseMethod("filter"): no applicable method for 'filter' applied to an object of class "function"
```

``` r
dt2=dt2[,c("PlV")]#keep only var of interest
```

```
## Error in eval(expr, envir, enclos): object 'dt2' not found
```

``` r
dt3=de %>% filter(Va==F) %>% group_by(chid) %>% mutate(LlnV=mean(Ll,na.rm=T))#avg Ll non-choices
```

```
## Error in UseMethod("filter"): no applicable method for 'filter' applied to an object of class "function"
```

``` r
dt3=dt3 %>% group_by(chid) %>% filter(row_number() == 1)#keep only one obs per respondent
```

```
## Error in eval(expr, envir, enclos): object 'dt3' not found
```

``` r
dt3=dt3[,c("LlnV")]#keep only var of interest
```

```
## Error in eval(expr, envir, enclos): object 'dt3' not found
```

``` r
dt4=de %>% filter(Va==T) %>% group_by(chid) %>% mutate(LlV=mean(Ll,na.rm=T))#Ll choices
```

```
## Error in UseMethod("filter"): no applicable method for 'filter' applied to an object of class "function"
```

``` r
dt4=dt4[,c("LlV")]#keep only var of interest
```

```
## Error in eval(expr, envir, enclos): object 'dt4' not found
```

``` r
dt=cbind(dt1,dt2,dt3,dt4)
```

```
## Error in eval(expr, envir, enclos): object 'dt1' not found
```

``` r
rm(dt1,dt2,dt3,dt4)

dt$PlVnV=dt$PlV-dt$PlnV
```

```
## Error in dt$PlV: object of type 'closure' is not subsettable
```

``` r
dt$LlVnV=dt$LlV-dt$LlnV
```

```
## Error in dt$LlV: object of type 'closure' is not subsettable
```

``` r
#base for stargazer non robust regressions:
LM_PlVnVMnwsp=lm(PlVnV ~ Mnwsp, data=dt)
```

```
## Error in model.frame.default(formula = PlVnV ~ Mnwsp, data = dt, drop.unused.levels = TRUE): 'data' must be a data.frame, environment, or list
```

``` r
LM_PlVnVMradi=lm(PlVnV ~ Mradi, data=dt)
```

```
## Error in model.frame.default(formula = PlVnV ~ Mradi, data = dt, drop.unused.levels = TRUE): 'data' must be a data.frame, environment, or list
```

``` r
LM_PlVnVMtele=lm(PlVnV ~ Mtele, data=dt)
```

```
## Error in model.frame.default(formula = PlVnV ~ Mtele, data = dt, drop.unused.levels = TRUE): 'data' must be a data.frame, environment, or list
```

``` r
LM_PlVnVMinte=lm(PlVnV ~ Minte, data=dt)
```

```
## Error in model.frame.default(formula = PlVnV ~ Minte, data = dt, drop.unused.levels = TRUE): 'data' must be a data.frame, environment, or list
```

``` r
LM_LlVnVMnwsp=lm(LlVnV ~ Mnwsp, data=dt)
```

```
## Error in model.frame.default(formula = LlVnV ~ Mnwsp, data = dt, drop.unused.levels = TRUE): 'data' must be a data.frame, environment, or list
```

``` r
LM_LlVnVMradi=lm(LlVnV ~ Mradi, data=dt)
```

```
## Error in model.frame.default(formula = LlVnV ~ Mradi, data = dt, drop.unused.levels = TRUE): 'data' must be a data.frame, environment, or list
```

``` r
LM_LlVnVMtele=lm(LlVnV ~ Mtele, data=dt)
```

```
## Error in model.frame.default(formula = LlVnV ~ Mtele, data = dt, drop.unused.levels = TRUE): 'data' must be a data.frame, environment, or list
```

``` r
LM_LlVnVMinte=lm(LlVnV ~ Minte, data=dt)
```

```
## Error in model.frame.default(formula = LlVnV ~ Minte, data = dt, drop.unused.levels = TRUE): 'data' must be a data.frame, environment, or list
```

``` r
#robust regressions:
LMR_PlVnVMnwsp=lm_robust(PlVnV ~ Mnwsp, data=dt, cluster=chid, se_type="stata")
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LMR_PlVnVMradi=lm_robust(PlVnV ~ Mradi, data=dt, cluster=chid, se_type="stata")
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LMR_PlVnVMtele=lm_robust(PlVnV ~ Mtele, data=dt, cluster=chid, se_type="stata")
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LMR_PlVnVMinte=lm_robust(PlVnV ~ Minte, data=dt, cluster=chid, se_type="stata")
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LMR_LlVnVMnwsp=lm_robust(LlVnV ~ Mnwsp, data=dt, cluster=chid, se_type="stata")
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LMR_LlVnVMradi=lm_robust(LlVnV ~ Mradi, data=dt, cluster=chid, se_type="stata")
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LMR_LlVnVMtele=lm_robust(LlVnV ~ Mtele, data=dt, cluster=chid, se_type="stata")
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
LMR_LlVnVMinte=lm_robust(LlVnV ~ Minte, data=dt, cluster=chid, se_type="stata")
```

```
## Error:
## ! `data` must be a vector, list, data frame, or environment
```

``` r
#change names for stargazer:
names(LM_PlVnVMnwsp$coefficients)[names(LM_PlVnVMnwsp$coefficients)=="Mnwsp"]="Media Use"
```

```
## Error: object 'LM_PlVnVMnwsp' not found
```

``` r
names(LM_PlVnVMradi$coefficients)[names(LM_PlVnVMradi$coefficients)=="Mradi"]="Media Use"
```

```
## Error: object 'LM_PlVnVMradi' not found
```

``` r
names(LM_PlVnVMtele$coefficients)[names(LM_PlVnVMtele$coefficients)=="Mtele"]="Media Use"
```

```
## Error: object 'LM_PlVnVMtele' not found
```

``` r
names(LM_PlVnVMinte$coefficients)[names(LM_PlVnVMinte$coefficients)=="Minte"]="Media Use"
```

```
## Error: object 'LM_PlVnVMinte' not found
```

``` r
names(LM_LlVnVMnwsp$coefficients)[names(LM_LlVnVMnwsp$coefficients)=="Mnwsp"]="Media Use"
```

```
## Error: object 'LM_LlVnVMnwsp' not found
```

``` r
names(LM_LlVnVMradi$coefficients)[names(LM_LlVnVMradi$coefficients)=="Mradi"]="Media Use"
```

```
## Error: object 'LM_LlVnVMradi' not found
```

``` r
names(LM_LlVnVMtele$coefficients)[names(LM_LlVnVMtele$coefficients)=="Mtele"]="Media Use"
```

```
## Error: object 'LM_LlVnVMtele' not found
```

``` r
names(LM_LlVnVMinte$coefficients)[names(LM_LlVnVMinte$coefficients)=="Minte"]="Media Use"
```

```
## Error: object 'LM_LlVnVMinte' not found
```

``` r
names(LMR_PlVnVMnwsp$std.error)[names(LMR_PlVnVMnwsp$std.error)=="Mnwsp"]="Media Use"
```

```
## Error: object 'LMR_PlVnVMnwsp' not found
```

``` r
names(LMR_PlVnVMradi$std.error)[names(LMR_PlVnVMradi$std.error)=="Mradi"]="Media Use"
```

```
## Error: object 'LMR_PlVnVMradi' not found
```

``` r
names(LMR_PlVnVMtele$std.error)[names(LMR_PlVnVMtele$std.error)=="Mtele"]="Media Use"
```

```
## Error: object 'LMR_PlVnVMtele' not found
```

``` r
names(LMR_PlVnVMinte$std.error)[names(LMR_PlVnVMinte$std.error)=="Minte"]="Media Use"
```

```
## Error: object 'LMR_PlVnVMinte' not found
```

``` r
names(LMR_LlVnVMnwsp$std.error)[names(LMR_LlVnVMnwsp$std.error)=="Mnwsp"]="Media Use"
```

```
## Error: object 'LMR_LlVnVMnwsp' not found
```

``` r
names(LMR_LlVnVMradi$std.error)[names(LMR_LlVnVMradi$std.error)=="Mradi"]="Media Use"
```

```
## Error: object 'LMR_LlVnVMradi' not found
```

``` r
names(LMR_LlVnVMtele$std.error)[names(LMR_LlVnVMtele$std.error)=="Mtele"]="Media Use"
```

```
## Error: object 'LMR_LlVnVMtele' not found
```

``` r
names(LMR_LlVnVMinte$std.error)[names(LMR_LlVnVMinte$std.error)=="Minte"]="Media Use"
```

```
## Error: object 'LMR_LlVnVMinte' not found
```

``` r
##Table 5##
#table:
stargazer(LM_PlVnVMnwsp,LM_PlVnVMradi,LM_PlVnVMtele,LM_PlVnVMinte,
          se = list(LMR_PlVnVMnwsp$std.error,LMR_PlVnVMradi$std.error,LMR_PlVnVMtele$std.error,LMR_PlVnVMinte$std.error) )
```

```
## Error in eval(expr, envir, enclos): object 'LM_PlVnVMnwsp' not found
```

``` r
stargazer(LM_LlVnVMnwsp,LM_LlVnVMradi,LM_LlVnVMtele,LM_LlVnVMinte,
          se = list(LMR_LlVnVMnwsp$std.error,LMR_LlVnVMradi$std.error,LMR_LlVnVMtele$std.error,LMR_LlVnVMinte$std.error) )
```

```
## Error in eval(expr, envir, enclos): object 'LM_LlVnVMnwsp' not found
```

``` r
#media PlV-PlnV impact on Pl-Ll:
CLC_base=clogit(Va ~ Pl+Ll+strata(chid), robust=T, data=de, method="efron")#base effect
```

```
## Error in model.frame.default(formula = Va ~ Pl + Ll + strata(chid), data = de, : 'data' must be a data.frame, environment, or list
```

``` r
CLC_base$coefficients["Pl"]-CLC_base$coefficients["Ll"]#0.689134#Pl-Ll base effect
```

```
## Error in eval(expr, envir, enclos): object 'CLC_base' not found
```

``` r
dte=de
dte$Pl[dte$Va==T]=dte$Pl[dte$Va==T]+(CI.LMMediafun(LM_Mtele_0,0)[22,1]-CI.LMMediafun(LM_Mtele_0,0)[12,1])*LM_PlVnVMtele$coefficients[2]
```

```
## Error in dte$Pl: object of type 'closure' is not subsettable
```

``` r
dte$Ll[dte$Va==T]=dte$Ll[dte$Va==T]+(CI.LMMediafun(LM_Mtele_0,0)[22,1]-CI.LMMediafun(LM_Mtele_0,0)[12,1])*LM_LlVnVMtele$coefficients[2]
```

```
## Error in dte$Ll: object of type 'closure' is not subsettable
```

``` r
CLC_LMRVnVMtele=clogit(Va ~ Pl+Ll+strata(chid), robust=T, data=dte, method="efron")#w/ media effect
```

```
## Error in model.frame.default(formula = Va ~ Pl + Ll + strata(chid), data = dte, : 'data' must be a data.frame, environment, or list
```

``` r
CLC_LMRVnVMtele$coefficients["Pl"]-CLC_LMRVnVMtele$coefficients["Ll"]#0.6865852#Pl-Ll w/ media effect
```

```
## Error in eval(expr, envir, enclos): object 'CLC_LMRVnVMtele' not found
```

``` r
# (Pl-Ll w/ media effect) - (Pl-Ll base effect):
CLC_LMRVnVMtele$coefficients["Pl"]-CLC_LMRVnVMtele$coefficients["Ll"]-(CLC_base$coefficients["Pl"]-CLC_base$coefficients["Ll"])
```

```
## Error in eval(expr, envir, enclos): object 'CLC_LMRVnVMtele' not found
```

``` r
#-0.002548789

#Z-test:
m=-0.037-(-0.0025)#residual drop = drop in 90s - drop due to Mtele effect on Pl,Ll
# (drop in 90s from Party/Leader Effect - 10 Years Segment Models)
se=0.011#standard error drop in 90s
z=m/se#Z score
p=2*pnorm(-abs(z))#p-value != (two tails)
p#0.001
```

```
## [1] 0.00171057
```

``` r
#the 90s drop remains significant even factoring out the possible effect of Mtele on Pl,Ll


#RC WITH BIGGEST 3 PARTIES - READ DATA 3 PARTIES:----

#read data:
load("d29_NP3.RData")
```

```
## Error in readChar(con, 5L, useBytes = TRUE): cannot open the connection
```

``` r
#base for country-slope FE:
#Ec:Pl FE:
for (i1 in 1:length(sort(unique(de$Ec)))) {#creating dummy variables Ec:Pl (for FE)
  de[[paste0("Pl_",sort(unique(de$Ec))[i1])]]=ifelse(de$Ec==sort(unique(de$Ec))[i1],de$Pl,0)#de$Pl
}
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
#Ec:Ll FE:
for (i1 in 1:length(sort(unique(de$Ec)))) {#creating dummy variables Ec:Ll (for FE)
  de[[paste0("Ll_",sort(unique(de$Ec))[i1])]]=ifelse(de$Ec==sort(unique(de$Ec))[i1],de$Ll,0)#de$Ll
}
```

```
## Error in de$Ec: object of type 'closure' is not subsettable
```

``` r
#base for density plots:
#create dataset density all data:
dyALL = de[!is.na(de$Va)&!is.na(de$Pl)&!is.na(de$Ll),] %>% group_by(Ey) %>% mutate(Eyn=n())#number of obs by Ey
```

```
## Error in de$Va: object of type 'closure' is not subsettable
```

``` r
dyALL$Eyn=dyALL$Eyn/1020288#density by Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
dyALL=dyALL %>% group_by(Ey) %>% filter(row_number()==1)#keep only 1 obs per Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
#create dataset density data with left-right self reported position:
dyLRR = de[!is.na(de$Va)&!is.na(de$Pl)&!is.na(de$Ll)&!is.na(de$LRR),] %>% group_by(Ey) %>% mutate(Eyn=n())#number of obs by Ey
```

```
## Error in de$Va: object of type 'closure' is not subsettable
```

``` r
dyLRR$Eyn=dyLRR$Eyn/1020288#density by Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyLRR' not found
```

``` r
dyLRR=dyLRR %>% group_by(Ey) %>% filter(row_number()==1)#keep only 1 obs per Ey
```

```
## Error in eval(expr, envir, enclos): object 'dyLRR' not found
```

``` r
#RC WITH BIGGEST 3 PARTIES - 10Y SEGMENTS:----

#confidence interval functions:
CI.PlLllses10fun=function(CLC,t0,pe){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=4)#Pl:
  for (t in 1:59) {
    # t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.PlLl[t,1]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6-
      (CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]-
      2*1*1*vcov(CLC)["Pl_ISL","Ll_ISL"]+2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  if (pe==1) {CI.PlLl=CI.PlLl[1:(10+t0),]}
  if (pe==2) {CI.PlLl=CI.PlLl[(11+t0):(20+t0),]}
  if (pe==3) {CI.PlLl=CI.PlLl[(21+t0):(30+t0),]}
  if (pe==4) {CI.PlLl=CI.PlLl[(31+t0):(40+t0),]}
  if (pe==5) {CI.PlLl=CI.PlLl[(41+t0):(50+t0),]}
  if (pe==6) {CI.PlLl=CI.PlLl[(51+t0):59,]}
  CI.PlLl
}
CI.Pllses10fun=function(CLC,t0,pe){ #function creating Confidence Interval for Pl
  CI.Pl=matrix(NA,nrow=59,ncol=4)#Pl:
  for (t in 1:59) {
    # t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.Pl[t,1]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6#fitted values
    CI.Pl[t,2]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]+2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6"]+
      2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]+2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]+
      2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]+
      2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]#Variance
    CI.Pl[t,3]=CI.Pl[t,1]-qnorm(0.975)*sqrt(CI.Pl[t,2])#95% CI lower
    CI.Pl[t,4]=CI.Pl[t,1]+qnorm(0.975)*sqrt(CI.Pl[t,2])#95% CI upper
  }
  CI.Pl=as.data.frame(CI.Pl)
  CI.Pl$t=c(1961:2019)
  if (pe==1) {CI.Pl=CI.Pl[1:(10+t0),]}
  if (pe==2) {CI.Pl=CI.Pl[(11+t0):(20+t0),]}
  if (pe==3) {CI.Pl=CI.Pl[(21+t0):(30+t0),]}
  if (pe==4) {CI.Pl=CI.Pl[(31+t0):(40+t0),]}
  if (pe==5) {CI.Pl=CI.Pl[(41+t0):(50+t0),]}
  if (pe==6) {CI.Pl=CI.Pl[(51+t0):59,]}
  CI.Pl
}
CI.Lllses10fun=function(CLC,t0,pe){ #function creating Confidence Interval for Ll
  CI.Ll=matrix(NA,nrow=59,ncol=4)#Ll:
  for (t in 1:59) {
    # t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.Ll[t,1]=CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6#fitted values
    CI.Ll[t,2]=1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]+
      2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]+
      2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]+
      2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]+
      2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]+
      2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]#Variance
    CI.Ll[t,3]=CI.Ll[t,1]-qnorm(0.975)*sqrt(CI.Ll[t,2])#95% CI lower
    CI.Ll[t,4]=CI.Ll[t,1]+qnorm(0.975)*sqrt(CI.Ll[t,2])#95% CI upper
  }
  CI.Ll=as.data.frame(CI.Ll)
  CI.Ll$t=c(1961:2019)
  if (pe==1) {CI.Ll=CI.Ll[1:(10+t0),]}
  if (pe==2) {CI.Ll=CI.Ll[(11+t0):(20+t0),]}
  if (pe==3) {CI.Ll=CI.Ll[(21+t0):(30+t0),]}
  if (pe==4) {CI.Ll=CI.Ll[(31+t0):(40+t0),]}
  if (pe==5) {CI.Ll=CI.Ll[(41+t0):(50+t0),]}
  if (pe==6) {CI.Ll=CI.Ll[(51+t0):59,]}
  CI.Ll
}

#Z-test functions:
ZtestfunT12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2)]-CLC$coefficients[paste0("Ll:time",2)]#mean
  v=vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2)]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunT=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}

#time variables:
t0=0#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
CLC_lses103_ea_0=clogit(Va ~ Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                          +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                        +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time2 + Ll:time2 + Pl:time3 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_lses103_ea_0$coefficients)[names(CLC_lses103_ea_0$coefficients)=="time2:Ll"]="Ll:time2"
```

```
## Error: object 'CLC_lses103_ea_0' not found
```

``` r
##Table F1##
#table (hypothesis testing):
stargazer(CLC_lses103_ea_0,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_ea_0' not found
```

``` r
ZtestfunT12(CLC_lses103_ea_0)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_ea_0' not found
```

``` r
ZtestfunT(CLC_lses103_ea_0,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_ea_0' not found
```

``` r
ZtestfunT(CLC_lses103_ea_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_ea_0' not found
```

``` r
ZtestfunT(CLC_lses103_ea_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_ea_0' not found
```

``` r
ZtestfunT(CLC_lses103_ea_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_ea_0' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses103","_PlLl_0.tex"),width=4, height=3)#plot Pl-Ll:
plot( ggplot() +ggtitle("")
      +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10fun(CLC_lses103_ea_0,0,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10fun(CLC_lses103_ea_0,0,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10fun(CLC_lses103_ea_0,0,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10fun(CLC_lses103_ea_0,0,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10fun(CLC_lses103_ea_0,0,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.PlLllses10fun(CLC_lses103_ea_0,0,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##Figure F1##
##plots only Pl,Ll:
# tikz(paste0("plot_","CLC_lses103","_Pl_0.tex"),width=4, height=3)#plot Pl:
plot( ggplot()
      +ggtitle("")
      +xlab("Year") +ylab("Party Effect") + coord_cartesian(ylim=c(0.5001,0.7)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.7-0.5001)+0.5001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses103_ea_0,0,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses103_ea_0,0,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses103_ea_0,0,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses103_ea_0,0,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses103_ea_0,0,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Pllses10fun(CLC_lses103_ea_0,0,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()
# tikz(paste0("plot_","CLC_lses103","_Ll_0.tex"),width=4, height=3)#plot Ll:
plot( ggplot()
      +ggtitle("")
      +xlab("Year") +ylab("Leader Effect") + coord_cartesian(ylim=c(0.0001,0.2)) + scale_y_continuous(expand=c(0,0)) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.2-0.0001)+0.0001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses103_ea_0,0,1)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses103_ea_0,0,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses103_ea_0,0,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses103_ea_0,0,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses103_ea_0,0,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", lwd=2, CI.Lllses10fun(CLC_lses103_ea_0,0,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


#RC WITH BIGGEST 3 PARTIES - 10Y SEGMENTS BY LRR:----

#left-right - 0.25 quantile:
de=de %>% group_by(Es) %>% mutate(LRR25 = quantile(LRR,0.25,na.rm=TRUE))#0.25 quantile by Es (left)
```

```
## Error in UseMethod("group_by"): no applicable method for 'group_by' applied to an object of class "function"
```

``` r
de$DL=ifelse(de$LRR<de$LRR25,1,0)# left # population 1/4,3/4
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
de$DR=ifelse(de$LRR>=de$LRR25,1,0)# right
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
#confidence interval functions:
CI.PlLllses10LRfun=function(CLC,t0,pe){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=8)#Pl:
  for (t in 1:59) {
    t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.PlLl[t,1]=CLC$coefficients["Pl_DEU"]+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6+
      CLC$coefficients["Pl:time2:DL"]*t2+CLC$coefficients["Pl:time3:DL"]*t3+CLC$coefficients["Pl:time4:DL"]*t4+CLC$coefficients["Pl:time5:DL"]*t5+CLC$coefficients["Pl:time6:DL"]*t6-
      (CLC$coefficients["Ll_DEU"]+CLC$coefficients["time3:Ll"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6+
         CLC$coefficients["Ll:time2:DL"]*t2+CLC$coefficients["time3:Ll:DL"]*t3+CLC$coefficients["Ll:time4:DL"]*t4+CLC$coefficients["Ll:time5:DL"]*t5+CLC$coefficients["Ll:time6:DL"]*t6)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)["Pl_DEU","Pl_DEU"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      t2^2*vcov(CLC)["Pl:time2:DL","Pl:time2:DL"]+t3^2*vcov(CLC)["Pl:time3:DL","Pl:time3:DL"]+t4^2*vcov(CLC)["Pl:time4:DL","Pl:time4:DL"]+t5^2*vcov(CLC)["Pl:time5:DL","Pl:time5:DL"]+t6^2*vcov(CLC)["Pl:time6:DL","Pl:time6:DL"]+
      1*vcov(CLC)["Ll_DEU","Ll_DEU"]+t3^2*vcov(CLC)["time3:Ll","time3:Ll"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]+
      t2^2*vcov(CLC)["Ll:time2:DL","Ll:time2:DL"]+t3^2*vcov(CLC)["time3:Ll:DL","time3:Ll:DL"]+t4^2*vcov(CLC)["Ll:time4:DL","Ll:time4:DL"]+t5^2*vcov(CLC)["Ll:time5:DL","Ll:time5:DL"]+t6^2*vcov(CLC)["Ll:time6:DL","Ll:time6:DL"]-
      2*1*1*vcov(CLC)["Pl_DEU","Ll_DEU"]+2*1*t3*vcov(CLC)["Pl_DEU","Pl:time3"]-2*1*t3*vcov(CLC)["Pl_DEU","time3:Ll"]+
      2*1*t4*vcov(CLC)["Pl_DEU","Pl:time4"]-2*1*t4*vcov(CLC)["Pl_DEU","Ll:time4"]+2*1*t5*vcov(CLC)["Pl_DEU","Pl:time5"]-2*1*t5*vcov(CLC)["Pl_DEU","Ll:time5"]+2*1*t6*vcov(CLC)["Pl_DEU","Pl:time6"]-2*1*t6*vcov(CLC)["Pl_DEU","Ll:time6"]+
      2*1*t2*vcov(CLC)["Pl_DEU","Pl:time2:DL"]-2*1*t2*vcov(CLC)["Pl_DEU","Ll:time2:DL"]+2*1*t3*vcov(CLC)["Pl_DEU","Pl:time3:DL"]-2*1*t3*vcov(CLC)["Pl_DEU","time3:Ll:DL"]+
      2*1*t4*vcov(CLC)["Pl_DEU","Pl:time4:DL"]-2*1*t4*vcov(CLC)["Pl_DEU","Ll:time4:DL"]+2*1*t5*vcov(CLC)["Pl_DEU","Pl:time5:DL"]-2*1*t5*vcov(CLC)["Pl_DEU","Ll:time5:DL"]+2*1*t6*vcov(CLC)["Pl_DEU","Pl:time6:DL"]-2*1*t6*vcov(CLC)["Pl_DEU","Ll:time6:DL"]-
      2*1*t3*vcov(CLC)["Ll_DEU","Pl:time3"]+2*1*t3*vcov(CLC)["Ll_DEU","time3:Ll"]-
      2*1*t4*vcov(CLC)["Ll_DEU","Pl:time4"]+2*1*t4*vcov(CLC)["Ll_DEU","Ll:time4"]-2*1*t5*vcov(CLC)["Ll_DEU","Pl:time5"]+2*1*t5*vcov(CLC)["Ll_DEU","Ll:time5"]-2*1*t6*vcov(CLC)["Ll_DEU","Pl:time6"]+2*1*t6*vcov(CLC)["Ll_DEU","Ll:time6"]-
      2*1*t2*vcov(CLC)["Ll_DEU","Pl:time2:DL"]+2*1*t2*vcov(CLC)["Ll_DEU","Ll:time2:DL"]-2*1*t3*vcov(CLC)["Ll_DEU","Pl:time3:DL"]+2*1*t3*vcov(CLC)["Ll_DEU","time3:Ll:DL"]-
      2*1*t4*vcov(CLC)["Ll_DEU","Pl:time4:DL"]+2*1*t4*vcov(CLC)["Ll_DEU","Ll:time4:DL"]-2*1*t5*vcov(CLC)["Ll_DEU","Pl:time5:DL"]+2*1*t5*vcov(CLC)["Ll_DEU","Ll:time5:DL"]-2*1*t6*vcov(CLC)["Ll_DEU","Pl:time6:DL"]+2*1*t6*vcov(CLC)["Ll_DEU","Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3","time3:Ll"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]+
      2*t3*t2*vcov(CLC)["Pl:time3","Pl:time2:DL"]-2*t3*t2*vcov(CLC)["Pl:time3","Ll:time2:DL"]+2*t3*t3*vcov(CLC)["Pl:time3","Pl:time3:DL"]-2*t3*t3*vcov(CLC)["Pl:time3","time3:Ll:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["time3:Ll","Pl:time4"]+2*t3*t4*vcov(CLC)["time3:Ll","Ll:time4"]-2*t3*t5*vcov(CLC)["time3:Ll","Pl:time5"]+2*t3*t5*vcov(CLC)["time3:Ll","Ll:time5"]-2*t3*t6*vcov(CLC)["time3:Ll","Pl:time6"]+2*t3*t6*vcov(CLC)["time3:Ll","Ll:time6"]-
      2*t3*t2*vcov(CLC)["time3:Ll","Pl:time2:DL"]+2*t3*t2*vcov(CLC)["time3:Ll","Ll:time2:DL"]-2*t3*t3*vcov(CLC)["time3:Ll","Pl:time3:DL"]+2*t3*t3*vcov(CLC)["time3:Ll","time3:Ll:DL"]-
      2*t3*t4*vcov(CLC)["time3:Ll","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["time3:Ll","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["time3:Ll","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["time3:Ll","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["time3:Ll","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["time3:Ll","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]+
      2*t4*t2*vcov(CLC)["Pl:time4","Pl:time2:DL"]-2*t4*t2*vcov(CLC)["Pl:time4","Ll:time2:DL"]+2*t4*t3*vcov(CLC)["Pl:time4","Pl:time3:DL"]-2*t4*t3*vcov(CLC)["Pl:time4","time3:Ll:DL"]+
      2*t4*t4*vcov(CLC)["Pl:time4","Pl:time4:DL"]-2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t4*t2*vcov(CLC)["Ll:time4","Pl:time2:DL"]+2*t4*t2*vcov(CLC)["Ll:time4","Ll:time2:DL"]-2*t4*t3*vcov(CLC)["Ll:time4","Pl:time3:DL"]+2*t4*t3*vcov(CLC)["Ll:time4","time3:Ll:DL"]-
      2*t4*t4*vcov(CLC)["Ll:time4","Pl:time4:DL"]+2*t4*t4*vcov(CLC)["Ll:time4","Ll:time4:DL"]-2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]+
      2*t5*t2*vcov(CLC)["Pl:time5","Pl:time2:DL"]-2*t5*t2*vcov(CLC)["Pl:time5","Ll:time2:DL"]+2*t5*t3*vcov(CLC)["Pl:time5","Pl:time3:DL"]-2*t5*t3*vcov(CLC)["Pl:time5","time3:Ll:DL"]+
      2*t5*t4*vcov(CLC)["Pl:time5","Pl:time4:DL"]-2*t5*t4*vcov(CLC)["Pl:time5","Ll:time4:DL"]+2*t5*t5*vcov(CLC)["Pl:time5","Pl:time5:DL"]-2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t5*t2*vcov(CLC)["Ll:time5","Pl:time2:DL"]+2*t5*t2*vcov(CLC)["Ll:time5","Ll:time2:DL"]-2*t5*t3*vcov(CLC)["Ll:time5","Pl:time3:DL"]+2*t5*t3*vcov(CLC)["Ll:time5","time3:Ll:DL"]-
      2*t5*t4*vcov(CLC)["Ll:time5","Pl:time4:DL"]+2*t5*t4*vcov(CLC)["Ll:time5","Ll:time4:DL"]-2*t5*t5*vcov(CLC)["Ll:time5","Pl:time5:DL"]+2*t5*t5*vcov(CLC)["Ll:time5","Ll:time5:DL"]-2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]+
      2*t6*t2*vcov(CLC)["Pl:time6","Pl:time2:DL"]-2*t6*t2*vcov(CLC)["Pl:time6","Ll:time2:DL"]+2*t6*t3*vcov(CLC)["Pl:time6","Pl:time3:DL"]-2*t6*t3*vcov(CLC)["Pl:time6","time3:Ll:DL"]+
      2*t6*t4*vcov(CLC)["Pl:time6","Pl:time4:DL"]-2*t6*t4*vcov(CLC)["Pl:time6","Ll:time4:DL"]+2*t6*t5*vcov(CLC)["Pl:time6","Pl:time5:DL"]-2*t6*t5*vcov(CLC)["Pl:time6","Ll:time5:DL"]+2*t6*t6*vcov(CLC)["Pl:time6","Pl:time6:DL"]-2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6:DL"]-
      2*t6*t2*vcov(CLC)["Ll:time6","Pl:time2:DL"]+2*t6*t2*vcov(CLC)["Ll:time6","Ll:time2:DL"]-2*t6*t3*vcov(CLC)["Ll:time6","Pl:time3:DL"]+2*t6*t3*vcov(CLC)["Ll:time6","time3:Ll:DL"]-
      2*t6*t4*vcov(CLC)["Ll:time6","Pl:time4:DL"]+2*t6*t4*vcov(CLC)["Ll:time6","Ll:time4:DL"]-2*t6*t5*vcov(CLC)["Ll:time6","Pl:time5:DL"]+2*t6*t5*vcov(CLC)["Ll:time6","Ll:time5:DL"]-2*t6*t6*vcov(CLC)["Ll:time6","Pl:time6:DL"]+2*t6*t6*vcov(CLC)["Ll:time6","Ll:time6:DL"]-
      2*t2*t2*vcov(CLC)["Pl:time2:DL","Ll:time2:DL"]+2*t2*t3*vcov(CLC)["Pl:time2:DL","Pl:time3:DL"]-2*t2*t3*vcov(CLC)["Pl:time2:DL","time3:Ll:DL"]+
      2*t2*t4*vcov(CLC)["Pl:time2:DL","Pl:time4:DL"]-2*t2*t4*vcov(CLC)["Pl:time2:DL","Ll:time4:DL"]+2*t2*t5*vcov(CLC)["Pl:time2:DL","Pl:time5:DL"]-2*t2*t5*vcov(CLC)["Pl:time2:DL","Ll:time5:DL"]+2*t2*t6*vcov(CLC)["Pl:time2:DL","Pl:time6:DL"]-2*t2*t6*vcov(CLC)["Pl:time2:DL","Ll:time6:DL"]-
      2*t2*t3*vcov(CLC)["Ll:time2:DL","Pl:time3:DL"]+2*t2*t3*vcov(CLC)["Ll:time2:DL","time3:Ll:DL"]-
      2*t2*t4*vcov(CLC)["Ll:time2:DL","Pl:time4:DL"]+2*t2*t4*vcov(CLC)["Ll:time2:DL","Ll:time4:DL"]-2*t2*t5*vcov(CLC)["Ll:time2:DL","Pl:time5:DL"]+2*t2*t5*vcov(CLC)["Ll:time2:DL","Ll:time5:DL"]-2*t2*t6*vcov(CLC)["Ll:time2:DL","Pl:time6:DL"]+2*t2*t6*vcov(CLC)["Ll:time2:DL","Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3:DL","time3:Ll:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3:DL","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3:DL","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3:DL","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3:DL","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3:DL","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3:DL","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["time3:Ll:DL","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["time3:Ll:DL","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["time3:Ll:DL","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["time3:Ll:DL","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["time3:Ll:DL","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["time3:Ll:DL","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4:DL","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4:DL","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4:DL","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4:DL","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4:DL","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4:DL","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4:DL","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4:DL","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4:DL","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5:DL","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5:DL","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5:DL","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5:DL","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5:DL","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6:DL","Ll:time6:DL"]
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
    #right:
    CI.PlLl[t,5]=CLC$coefficients["Pl_DEU"]+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6-
      (CLC$coefficients["Ll_DEU"]+CLC$coefficients["time3:Ll"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6)#fitted values
    CI.PlLl[t,6]=1*vcov(CLC)["Pl_DEU","Pl_DEU"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      1*vcov(CLC)["Ll_DEU","Ll_DEU"]+t3^2*vcov(CLC)["time3:Ll","time3:Ll"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]-
      2*1*1*vcov(CLC)["Pl_DEU","Ll_DEU"]+2*1*t3*vcov(CLC)["Pl_DEU","Pl:time3"]-2*1*t3*vcov(CLC)["Pl_DEU","time3:Ll"]+
      2*1*t4*vcov(CLC)["Pl_DEU","Pl:time4"]-2*1*t4*vcov(CLC)["Pl_DEU","Ll:time4"]+2*1*t5*vcov(CLC)["Pl_DEU","Pl:time5"]-2*1*t5*vcov(CLC)["Pl_DEU","Ll:time5"]+2*1*t6*vcov(CLC)["Pl_DEU","Pl:time6"]-2*1*t6*vcov(CLC)["Pl_DEU","Ll:time6"]-
      2*1*t3*vcov(CLC)["Ll_DEU","Pl:time3"]+2*1*t3*vcov(CLC)["Ll_DEU","time3:Ll"]-
      2*1*t4*vcov(CLC)["Ll_DEU","Pl:time4"]+2*1*t4*vcov(CLC)["Ll_DEU","Ll:time4"]-2*1*t5*vcov(CLC)["Ll_DEU","Pl:time5"]+2*1*t5*vcov(CLC)["Ll_DEU","Ll:time5"]-2*1*t6*vcov(CLC)["Ll_DEU","Pl:time6"]+2*1*t6*vcov(CLC)["Ll_DEU","Ll:time6"]-
      2*t3*t3*vcov(CLC)["Pl:time3","time3:Ll"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]-
      2*t3*t4*vcov(CLC)["time3:Ll","Pl:time4"]+2*t3*t4*vcov(CLC)["time3:Ll","Ll:time4"]-2*t3*t5*vcov(CLC)["time3:Ll","Pl:time5"]+2*t3*t5*vcov(CLC)["time3:Ll","Ll:time5"]-2*t3*t6*vcov(CLC)["time3:Ll","Pl:time6"]+2*t3*t6*vcov(CLC)["time3:Ll","Ll:time6"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]
    CI.PlLl[t,7]=CI.PlLl[t,5]-qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI lower
    CI.PlLl[t,8]=CI.PlLl[t,5]+qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  if (pe==1) {CI.PlLl=CI.PlLl[1:(10+t0),]}
  if (pe==2) {CI.PlLl=CI.PlLl[(11+t0):(20+t0),]}
  if (pe==3) {CI.PlLl=CI.PlLl[(21+t0):(30+t0),]}
  if (pe==4) {CI.PlLl=CI.PlLl[(31+t0):(40+t0),]}
  if (pe==5) {CI.PlLl=CI.PlLl[(41+t0):(50+t0),]}
  if (pe==6) {CI.PlLl=CI.PlLl[(51+t0):59,]}
  CI.PlLl
}
CI.PlLllses10LRfunCTY=function(CLC,t0,pe,cty){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=8)#Pl:
  for (t in 1:59) {
    t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    CI.PlLl[t,1]=CLC$coefficients[paste0("Pl_",cty)]+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6+
      CLC$coefficients["Pl:time2:DL"]*t2+CLC$coefficients["Pl:time3:DL"]*t3+CLC$coefficients["Pl:time4:DL"]*t4+CLC$coefficients["Pl:time5:DL"]*t5+CLC$coefficients["Pl:time6:DL"]*t6-
      (CLC$coefficients[paste0("Ll_",cty)]+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6+
         CLC$coefficients["Ll:time2:DL"]*t2+CLC$coefficients["Ll:time3:DL"]*t3+CLC$coefficients["Ll:time4:DL"]*t4+CLC$coefficients["Ll:time5:DL"]*t5+CLC$coefficients["Ll:time6:DL"]*t6)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)[paste0("Pl_",cty),paste0("Pl_",cty)]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      t2^2*vcov(CLC)["Pl:time2:DL","Pl:time2:DL"]+t3^2*vcov(CLC)["Pl:time3:DL","Pl:time3:DL"]+t4^2*vcov(CLC)["Pl:time4:DL","Pl:time4:DL"]+t5^2*vcov(CLC)["Pl:time5:DL","Pl:time5:DL"]+t6^2*vcov(CLC)["Pl:time6:DL","Pl:time6:DL"]+
      1*vcov(CLC)[paste0("Ll_",cty),paste0("Ll_",cty)]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]+
      t2^2*vcov(CLC)["Ll:time2:DL","Ll:time2:DL"]+t3^2*vcov(CLC)["Ll:time3:DL","Ll:time3:DL"]+t4^2*vcov(CLC)["Ll:time4:DL","Ll:time4:DL"]+t5^2*vcov(CLC)["Ll:time5:DL","Ll:time5:DL"]+t6^2*vcov(CLC)["Ll:time6:DL","Ll:time6:DL"]-
      2*1*1*vcov(CLC)[paste0("Pl_",cty),paste0("Ll_",cty)]+2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Pl:time3"]-2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Ll:time3"]+
      2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Pl:time4"]-2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Ll:time4"]+2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Pl:time5"]-2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Ll:time5"]+2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Pl:time6"]-2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Ll:time6"]+
      2*1*t2*vcov(CLC)[paste0("Pl_",cty),"Pl:time2:DL"]-2*1*t2*vcov(CLC)[paste0("Pl_",cty),"Ll:time2:DL"]+2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Pl:time3:DL"]-2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Ll:time3:DL"]+
      2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Pl:time4:DL"]-2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Ll:time4:DL"]+2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Pl:time5:DL"]-2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Ll:time5:DL"]+2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Pl:time6:DL"]-2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Ll:time6:DL"]-
      2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Pl:time3"]+2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Ll:time3"]-
      2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Pl:time4"]+2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Ll:time4"]-2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Pl:time5"]+2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Ll:time5"]-2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Pl:time6"]+2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Ll:time6"]-
      2*1*t2*vcov(CLC)[paste0("Ll_",cty),"Pl:time2:DL"]+2*1*t2*vcov(CLC)[paste0("Ll_",cty),"Ll:time2:DL"]-2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Pl:time3:DL"]+2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Ll:time3:DL"]-
      2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Pl:time4:DL"]+2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Ll:time4:DL"]-2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Pl:time5:DL"]+2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Ll:time5:DL"]-2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Pl:time6:DL"]+2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]+
      2*t3*t2*vcov(CLC)["Pl:time3","Pl:time2:DL"]-2*t3*t2*vcov(CLC)["Pl:time3","Ll:time2:DL"]+2*t3*t3*vcov(CLC)["Pl:time3","Pl:time3:DL"]-2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t3*t2*vcov(CLC)["Ll:time3","Pl:time2:DL"]+2*t3*t2*vcov(CLC)["Ll:time3","Ll:time2:DL"]-2*t3*t3*vcov(CLC)["Ll:time3","Pl:time3:DL"]+2*t3*t3*vcov(CLC)["Ll:time3","Ll:time3:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]+
      2*t4*t2*vcov(CLC)["Pl:time4","Pl:time2:DL"]-2*t4*t2*vcov(CLC)["Pl:time4","Ll:time2:DL"]+2*t4*t3*vcov(CLC)["Pl:time4","Pl:time3:DL"]-2*t4*t3*vcov(CLC)["Pl:time4","Ll:time3:DL"]+
      2*t4*t4*vcov(CLC)["Pl:time4","Pl:time4:DL"]-2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t4*t2*vcov(CLC)["Ll:time4","Pl:time2:DL"]+2*t4*t2*vcov(CLC)["Ll:time4","Ll:time2:DL"]-2*t4*t3*vcov(CLC)["Ll:time4","Pl:time3:DL"]+2*t4*t3*vcov(CLC)["Ll:time4","Ll:time3:DL"]-
      2*t4*t4*vcov(CLC)["Ll:time4","Pl:time4:DL"]+2*t4*t4*vcov(CLC)["Ll:time4","Ll:time4:DL"]-2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]+
      2*t5*t2*vcov(CLC)["Pl:time5","Pl:time2:DL"]-2*t5*t2*vcov(CLC)["Pl:time5","Ll:time2:DL"]+2*t5*t3*vcov(CLC)["Pl:time5","Pl:time3:DL"]-2*t5*t3*vcov(CLC)["Pl:time5","Ll:time3:DL"]+
      2*t5*t4*vcov(CLC)["Pl:time5","Pl:time4:DL"]-2*t5*t4*vcov(CLC)["Pl:time5","Ll:time4:DL"]+2*t5*t5*vcov(CLC)["Pl:time5","Pl:time5:DL"]-2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t5*t2*vcov(CLC)["Ll:time5","Pl:time2:DL"]+2*t5*t2*vcov(CLC)["Ll:time5","Ll:time2:DL"]-2*t5*t3*vcov(CLC)["Ll:time5","Pl:time3:DL"]+2*t5*t3*vcov(CLC)["Ll:time5","Ll:time3:DL"]-
      2*t5*t4*vcov(CLC)["Ll:time5","Pl:time4:DL"]+2*t5*t4*vcov(CLC)["Ll:time5","Ll:time4:DL"]-2*t5*t5*vcov(CLC)["Ll:time5","Pl:time5:DL"]+2*t5*t5*vcov(CLC)["Ll:time5","Ll:time5:DL"]-2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]+
      2*t6*t2*vcov(CLC)["Pl:time6","Pl:time2:DL"]-2*t6*t2*vcov(CLC)["Pl:time6","Ll:time2:DL"]+2*t6*t3*vcov(CLC)["Pl:time6","Pl:time3:DL"]-2*t6*t3*vcov(CLC)["Pl:time6","Ll:time3:DL"]+
      2*t6*t4*vcov(CLC)["Pl:time6","Pl:time4:DL"]-2*t6*t4*vcov(CLC)["Pl:time6","Ll:time4:DL"]+2*t6*t5*vcov(CLC)["Pl:time6","Pl:time5:DL"]-2*t6*t5*vcov(CLC)["Pl:time6","Ll:time5:DL"]+2*t6*t6*vcov(CLC)["Pl:time6","Pl:time6:DL"]-2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6:DL"]-
      2*t6*t2*vcov(CLC)["Ll:time6","Pl:time2:DL"]+2*t6*t2*vcov(CLC)["Ll:time6","Ll:time2:DL"]-2*t6*t3*vcov(CLC)["Ll:time6","Pl:time3:DL"]+2*t6*t3*vcov(CLC)["Ll:time6","Ll:time3:DL"]-
      2*t6*t4*vcov(CLC)["Ll:time6","Pl:time4:DL"]+2*t6*t4*vcov(CLC)["Ll:time6","Ll:time4:DL"]-2*t6*t5*vcov(CLC)["Ll:time6","Pl:time5:DL"]+2*t6*t5*vcov(CLC)["Ll:time6","Ll:time5:DL"]-2*t6*t6*vcov(CLC)["Ll:time6","Pl:time6:DL"]+2*t6*t6*vcov(CLC)["Ll:time6","Ll:time6:DL"]-
      2*t2*t2*vcov(CLC)["Pl:time2:DL","Ll:time2:DL"]+2*t2*t3*vcov(CLC)["Pl:time2:DL","Pl:time3:DL"]-2*t2*t3*vcov(CLC)["Pl:time2:DL","Ll:time3:DL"]+
      2*t2*t4*vcov(CLC)["Pl:time2:DL","Pl:time4:DL"]-2*t2*t4*vcov(CLC)["Pl:time2:DL","Ll:time4:DL"]+2*t2*t5*vcov(CLC)["Pl:time2:DL","Pl:time5:DL"]-2*t2*t5*vcov(CLC)["Pl:time2:DL","Ll:time5:DL"]+2*t2*t6*vcov(CLC)["Pl:time2:DL","Pl:time6:DL"]-2*t2*t6*vcov(CLC)["Pl:time2:DL","Ll:time6:DL"]-
      2*t2*t3*vcov(CLC)["Ll:time2:DL","Pl:time3:DL"]+2*t2*t3*vcov(CLC)["Ll:time2:DL","Ll:time3:DL"]-
      2*t2*t4*vcov(CLC)["Ll:time2:DL","Pl:time4:DL"]+2*t2*t4*vcov(CLC)["Ll:time2:DL","Ll:time4:DL"]-2*t2*t5*vcov(CLC)["Ll:time2:DL","Pl:time5:DL"]+2*t2*t5*vcov(CLC)["Ll:time2:DL","Ll:time5:DL"]-2*t2*t6*vcov(CLC)["Ll:time2:DL","Pl:time6:DL"]+2*t2*t6*vcov(CLC)["Ll:time2:DL","Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3:DL","Ll:time3:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3:DL","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3:DL","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3:DL","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3:DL","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3:DL","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3:DL","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3:DL","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["Ll:time3:DL","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["Ll:time3:DL","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["Ll:time3:DL","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["Ll:time3:DL","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["Ll:time3:DL","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4:DL","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4:DL","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4:DL","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4:DL","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4:DL","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4:DL","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4:DL","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4:DL","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4:DL","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5:DL","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5:DL","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5:DL","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5:DL","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5:DL","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6:DL","Ll:time6:DL"]
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
    #right:
    CI.PlLl[t,5]=CLC$coefficients[paste0("Pl_",cty)]+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6-
      (CLC$coefficients[paste0("Ll_",cty)]+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6)#fitted values
    CI.PlLl[t,6]=1*vcov(CLC)[paste0("Pl_",cty),paste0("Pl_",cty)]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      1*vcov(CLC)[paste0("Ll_",cty),paste0("Ll_",cty)]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]-
      2*1*1*vcov(CLC)[paste0("Pl_",cty),paste0("Ll_",cty)]+2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Pl:time3"]-2*1*t3*vcov(CLC)[paste0("Pl_",cty),"Ll:time3"]+
      2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Pl:time4"]-2*1*t4*vcov(CLC)[paste0("Pl_",cty),"Ll:time4"]+2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Pl:time5"]-2*1*t5*vcov(CLC)[paste0("Pl_",cty),"Ll:time5"]+2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Pl:time6"]-2*1*t6*vcov(CLC)[paste0("Pl_",cty),"Ll:time6"]-
      2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Pl:time3"]+2*1*t3*vcov(CLC)[paste0("Ll_",cty),"Ll:time3"]-
      2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Pl:time4"]+2*1*t4*vcov(CLC)[paste0("Ll_",cty),"Ll:time4"]-2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Pl:time5"]+2*1*t5*vcov(CLC)[paste0("Ll_",cty),"Ll:time5"]-2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Pl:time6"]+2*1*t6*vcov(CLC)[paste0("Ll_",cty),"Ll:time6"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]
    CI.PlLl[t,7]=CI.PlLl[t,5]-qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI lower
    CI.PlLl[t,8]=CI.PlLl[t,5]+qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  if (pe==1) {CI.PlLl=CI.PlLl[1:(10+t0),]}
  if (pe==2) {CI.PlLl=CI.PlLl[(11+t0):(20+t0),]}
  if (pe==3) {CI.PlLl=CI.PlLl[(21+t0):(30+t0),]}
  if (pe==4) {CI.PlLl=CI.PlLl[(31+t0):(40+t0),]}
  if (pe==5) {CI.PlLl=CI.PlLl[(41+t0):(50+t0),]}
  if (pe==6) {CI.PlLl=CI.PlLl[(51+t0):59,]}
  CI.PlLl
}

#Z-test functions:
ZtestfunT12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2)]-CLC$coefficients[paste0("Ll:time",2)]#mean
  v=vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2)]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunTD12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2,":DL")]-CLC$coefficients[paste0("Ll:time",2,":DL")]#mean
  v=vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Pl:time",2,":DL")]+vcov(CLC)[paste0("Ll:time",2,":DL"),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Ll:time",2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunD12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2)]-CLC$coefficients[paste0("Ll:time",2)]+
    CLC$coefficients[paste0("Pl:time",2,":DL")]-CLC$coefficients[paste0("Ll:time",2,":DL")]#mean
  v=vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2)]+
    vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Pl:time",2,":DL")]+vcov(CLC)[paste0("Ll:time",2,":DL"),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2)]+2*vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",2),paste0("Pl:time",2,":DL")]+2*vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Ll:time",2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunT=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunTD=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1,":DL")]-CLC$coefficients[paste0("Ll:time",per1,":DL")]-
        CLC$coefficients[paste0("Pl:time",per2,":DL")]+CLC$coefficients[paste0("Ll:time",per2,":DL")])#mean
  v=vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per1,":DL")]+vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per1,":DL")]+
    vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Pl:time",per2,":DL")]+vcov(CLC)[paste0("Ll:time",per2,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2,":DL")]-2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Ll:time",per2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunD=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]+
        CLC$coefficients[paste0("Pl:time",per1,":DL")]-CLC$coefficients[paste0("Ll:time",per1,":DL")]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)]-
        CLC$coefficients[paste0("Pl:time",per2,":DL")]+CLC$coefficients[paste0("Ll:time",per2,":DL")])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per1,":DL")]+vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per1,":DL")]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]+
    vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Pl:time",per2,":DL")]+vcov(CLC)[paste0("Ll:time",per2,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]+2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per1,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1,":DL")]+2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2)]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2)]-
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per2),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Ll:time",per2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}

#time variables:
t0=0#starting value for thresholds (-4,-2,0,2,4)
de$time1=ifelse(de$time<=10+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regressions:
CLC_lses103_LR25_0=clogit(Va ~ Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                            Pl:time2:DL+Ll:time2:DL+Pl:time3:DL+Ll:time3:DL+Pl:time4:DL+Ll:time4:DL+Pl:time5:DL+Ll:time5:DL+Pl:time6:DL+Ll:time6:DL+
                            +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                          +strata(Esalt), robust=T, data=de[!is.na(de$LRR),], method="efron")#regression
```

```
## Error in de$LRR: object of type 'closure' is not subsettable
```

``` r
names(CLC_lses103_LR25_0$coefficients)[names(CLC_lses103_LR25_0$coefficients)=="time3:Ll"]="Ll:time3"
```

```
## Error: object 'CLC_lses103_LR25_0' not found
```

``` r
names(CLC_lses103_LR25_0$coefficients)[names(CLC_lses103_LR25_0$coefficients)=="time3:Ll:DL"]="Ll:time3:DL"
```

```
## Error: object 'CLC_lses103_LR25_0' not found
```

``` r
##Table F2##
#hypothesis testing:
stargazer(CLC_lses103_LR25_0,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_LR25_0' not found
```

``` r
#drop remaining voters:
ZtestfunT(CLC_lses103_LR25_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_LR25_0' not found
```

``` r
ZtestfunT(CLC_lses103_LR25_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_LR25_0' not found
```

``` r
ZtestfunT(CLC_lses103_LR25_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_LR25_0' not found
```

``` r
#drop left-quartile voters:
ZtestfunD(CLC_lses103_LR25_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_LR25_0' not found
```

``` r
ZtestfunD(CLC_lses103_LR25_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_LR25_0' not found
```

``` r
ZtestfunD(CLC_lses103_LR25_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_LR25_0' not found
```

``` r
#difference in drop between left-quartile and remaining voters:
ZtestfunTD(CLC_lses103_LR25_0,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_LR25_0' not found
```

``` r
ZtestfunTD(CLC_lses103_LR25_0,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_LR25_0' not found
```

``` r
ZtestfunTD(CLC_lses103_LR25_0,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_LR25_0' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses103_LR25_0","_PlLl.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.4001,0.64)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.4001)+0.4001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyLRR) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses103_LR25_0,0,3,sort(unique(de$Ec))[11])) +#left
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses103_LR25_0,0,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses103_LR25_0,0,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10LRfunCTY(CLC_lses103_LR25_0,0,6,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses103_LR25_0,0,3,sort(unique(de$Ec))[11])) +#right
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses103_LR25_0,0,4,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses103_LR25_0,0,5,sort(unique(de$Ec))[11])) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10LRfunCTY(CLC_lses103_LR25_0,0,6,sort(unique(de$Ec))[11])) )
```

```
## Error in eval(expr, envir, enclos): object 'dyLRR' not found
```

``` r
# dev.off()


#RC WITH BIGGEST 3 PARTIES - 10Y SEGMENTS BY COUNTRY GERMANY AND TABLE:----

#Germany dummy:
de$DL[de$Ec %in% c("DEU")]=1#(high)
```

```
## Error in `*tmp*`$DL: object of type 'closure' is not subsettable
```

``` r
de$DL[!de$Ec %in% c("DEU")]=0#(low)
```

```
## Error in `*tmp*`$DL: object of type 'closure' is not subsettable
```

``` r
#confidence interval functions:
CI.PlLllses10CGfun=function(CLC,t0,pe){ #function creating Confidence Interval for Pl-Ll
  CI.PlLl=matrix(NA,nrow=59,ncol=8)#Pl:
  for (t in 1:59) {
    t1=ifelse(t<=10+t0,1,0)
    t2=ifelse(t>10+t0&t<=20+t0,1,0)
    t3=ifelse(t>20+t0&t<=30+t0,1,0)
    t4=ifelse(t>30+t0&t<=40+t0,1,0)
    t5=ifelse(t>40+t0&t<=50+t0,1,0)
    t6=ifelse(t>50+t0,1,0)
    #left:
    CI.PlLl[t,1]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6+
      CLC$coefficients["Pl:time2:DL"]*t2+CLC$coefficients["Pl:time3:DL"]*t3+CLC$coefficients["Pl:time4:DL"]*t4+CLC$coefficients["Pl:time5:DL"]*t5+CLC$coefficients["Pl:time6:DL"]*t6-
      (CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6+
         CLC$coefficients["Ll:time2:DL"]*t2+CLC$coefficients["Ll:time3:DL"]*t3+CLC$coefficients["Ll:time4:DL"]*t4+CLC$coefficients["Ll:time5:DL"]*t5+CLC$coefficients["Ll:time6:DL"]*t6)#fitted values
    CI.PlLl[t,2]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      t2^2*vcov(CLC)["Pl:time2:DL","Pl:time2:DL"]+t3^2*vcov(CLC)["Pl:time3:DL","Pl:time3:DL"]+t4^2*vcov(CLC)["Pl:time4:DL","Pl:time4:DL"]+t5^2*vcov(CLC)["Pl:time5:DL","Pl:time5:DL"]+t6^2*vcov(CLC)["Pl:time6:DL","Pl:time6:DL"]+
      1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]+
      t2^2*vcov(CLC)["Ll:time2:DL","Ll:time2:DL"]+t3^2*vcov(CLC)["Ll:time3:DL","Ll:time3:DL"]+t4^2*vcov(CLC)["Ll:time4:DL","Ll:time4:DL"]+t5^2*vcov(CLC)["Ll:time5:DL","Ll:time5:DL"]+t6^2*vcov(CLC)["Ll:time6:DL","Ll:time6:DL"]-
      2*1*1*vcov(CLC)["Pl_ISL","Ll_ISL"]+2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6"]+
      2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2:DL"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2:DL"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3:DL"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3:DL"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4:DL"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4:DL"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5:DL"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5:DL"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6:DL"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6:DL"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2:DL"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2:DL"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3:DL"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3:DL"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4:DL"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4:DL"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5:DL"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5:DL"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6:DL"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6:DL"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6"]+
      2*t2*t2*vcov(CLC)["Pl:time2","Pl:time2:DL"]-2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2:DL"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3:DL"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3:DL"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4:DL"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4:DL"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5:DL"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5:DL"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6:DL"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6:DL"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]-
      2*t2*t2*vcov(CLC)["Ll:time2","Pl:time2:DL"]+2*t2*t2*vcov(CLC)["Ll:time2","Ll:time2:DL"]-2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3:DL"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3:DL"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4:DL"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4:DL"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5:DL"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5:DL"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6:DL"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]+
      2*t3*t2*vcov(CLC)["Pl:time3","Pl:time2:DL"]-2*t3*t2*vcov(CLC)["Pl:time3","Ll:time2:DL"]+2*t3*t3*vcov(CLC)["Pl:time3","Pl:time3:DL"]-2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t3*t2*vcov(CLC)["Ll:time3","Pl:time2:DL"]+2*t3*t2*vcov(CLC)["Ll:time3","Ll:time2:DL"]-2*t3*t3*vcov(CLC)["Ll:time3","Pl:time3:DL"]+2*t3*t3*vcov(CLC)["Ll:time3","Ll:time3:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]+
      2*t4*t2*vcov(CLC)["Pl:time4","Pl:time2:DL"]-2*t4*t2*vcov(CLC)["Pl:time4","Ll:time2:DL"]+2*t4*t3*vcov(CLC)["Pl:time4","Pl:time3:DL"]-2*t4*t3*vcov(CLC)["Pl:time4","Ll:time3:DL"]+
      2*t4*t4*vcov(CLC)["Pl:time4","Pl:time4:DL"]-2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t4*t2*vcov(CLC)["Ll:time4","Pl:time2:DL"]+2*t4*t2*vcov(CLC)["Ll:time4","Ll:time2:DL"]-2*t4*t3*vcov(CLC)["Ll:time4","Pl:time3:DL"]+2*t4*t3*vcov(CLC)["Ll:time4","Ll:time3:DL"]-
      2*t4*t4*vcov(CLC)["Ll:time4","Pl:time4:DL"]+2*t4*t4*vcov(CLC)["Ll:time4","Ll:time4:DL"]-2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]+
      2*t5*t2*vcov(CLC)["Pl:time5","Pl:time2:DL"]-2*t5*t2*vcov(CLC)["Pl:time5","Ll:time2:DL"]+2*t5*t3*vcov(CLC)["Pl:time5","Pl:time3:DL"]-2*t5*t3*vcov(CLC)["Pl:time5","Ll:time3:DL"]+
      2*t5*t4*vcov(CLC)["Pl:time5","Pl:time4:DL"]-2*t5*t4*vcov(CLC)["Pl:time5","Ll:time4:DL"]+2*t5*t5*vcov(CLC)["Pl:time5","Pl:time5:DL"]-2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t5*t2*vcov(CLC)["Ll:time5","Pl:time2:DL"]+2*t5*t2*vcov(CLC)["Ll:time5","Ll:time2:DL"]-2*t5*t3*vcov(CLC)["Ll:time5","Pl:time3:DL"]+2*t5*t3*vcov(CLC)["Ll:time5","Ll:time3:DL"]-
      2*t5*t4*vcov(CLC)["Ll:time5","Pl:time4:DL"]+2*t5*t4*vcov(CLC)["Ll:time5","Ll:time4:DL"]-2*t5*t5*vcov(CLC)["Ll:time5","Pl:time5:DL"]+2*t5*t5*vcov(CLC)["Ll:time5","Ll:time5:DL"]-2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]+
      2*t6*t2*vcov(CLC)["Pl:time6","Pl:time2:DL"]-2*t6*t2*vcov(CLC)["Pl:time6","Ll:time2:DL"]+2*t6*t3*vcov(CLC)["Pl:time6","Pl:time3:DL"]-2*t6*t3*vcov(CLC)["Pl:time6","Ll:time3:DL"]+
      2*t6*t4*vcov(CLC)["Pl:time6","Pl:time4:DL"]-2*t6*t4*vcov(CLC)["Pl:time6","Ll:time4:DL"]+2*t6*t5*vcov(CLC)["Pl:time6","Pl:time5:DL"]-2*t6*t5*vcov(CLC)["Pl:time6","Ll:time5:DL"]+2*t6*t6*vcov(CLC)["Pl:time6","Pl:time6:DL"]-2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6:DL"]-
      2*t6*t2*vcov(CLC)["Ll:time6","Pl:time2:DL"]+2*t6*t2*vcov(CLC)["Ll:time6","Ll:time2:DL"]-2*t6*t3*vcov(CLC)["Ll:time6","Pl:time3:DL"]+2*t6*t3*vcov(CLC)["Ll:time6","Ll:time3:DL"]-
      2*t6*t4*vcov(CLC)["Ll:time6","Pl:time4:DL"]+2*t6*t4*vcov(CLC)["Ll:time6","Ll:time4:DL"]-2*t6*t5*vcov(CLC)["Ll:time6","Pl:time5:DL"]+2*t6*t5*vcov(CLC)["Ll:time6","Ll:time5:DL"]-2*t6*t6*vcov(CLC)["Ll:time6","Pl:time6:DL"]+2*t6*t6*vcov(CLC)["Ll:time6","Ll:time6:DL"]-
      2*t2*t2*vcov(CLC)["Pl:time2:DL","Ll:time2:DL"]+2*t2*t3*vcov(CLC)["Pl:time2:DL","Pl:time3:DL"]-2*t2*t3*vcov(CLC)["Pl:time2:DL","Ll:time3:DL"]+
      2*t2*t4*vcov(CLC)["Pl:time2:DL","Pl:time4:DL"]-2*t2*t4*vcov(CLC)["Pl:time2:DL","Ll:time4:DL"]+2*t2*t5*vcov(CLC)["Pl:time2:DL","Pl:time5:DL"]-2*t2*t5*vcov(CLC)["Pl:time2:DL","Ll:time5:DL"]+2*t2*t6*vcov(CLC)["Pl:time2:DL","Pl:time6:DL"]-2*t2*t6*vcov(CLC)["Pl:time2:DL","Ll:time6:DL"]-
      2*t2*t3*vcov(CLC)["Ll:time2:DL","Pl:time3:DL"]+2*t2*t3*vcov(CLC)["Ll:time2:DL","Ll:time3:DL"]-
      2*t2*t4*vcov(CLC)["Ll:time2:DL","Pl:time4:DL"]+2*t2*t4*vcov(CLC)["Ll:time2:DL","Ll:time4:DL"]-2*t2*t5*vcov(CLC)["Ll:time2:DL","Pl:time5:DL"]+2*t2*t5*vcov(CLC)["Ll:time2:DL","Ll:time5:DL"]-2*t2*t6*vcov(CLC)["Ll:time2:DL","Pl:time6:DL"]+2*t2*t6*vcov(CLC)["Ll:time2:DL","Ll:time6:DL"]-
      2*t3*t3*vcov(CLC)["Pl:time3:DL","Ll:time3:DL"]+
      2*t3*t4*vcov(CLC)["Pl:time3:DL","Pl:time4:DL"]-2*t3*t4*vcov(CLC)["Pl:time3:DL","Ll:time4:DL"]+2*t3*t5*vcov(CLC)["Pl:time3:DL","Pl:time5:DL"]-2*t3*t5*vcov(CLC)["Pl:time3:DL","Ll:time5:DL"]+2*t3*t6*vcov(CLC)["Pl:time3:DL","Pl:time6:DL"]-2*t3*t6*vcov(CLC)["Pl:time3:DL","Ll:time6:DL"]-
      2*t3*t4*vcov(CLC)["Ll:time3:DL","Pl:time4:DL"]+2*t3*t4*vcov(CLC)["Ll:time3:DL","Ll:time4:DL"]-2*t3*t5*vcov(CLC)["Ll:time3:DL","Pl:time5:DL"]+2*t3*t5*vcov(CLC)["Ll:time3:DL","Ll:time5:DL"]-2*t3*t6*vcov(CLC)["Ll:time3:DL","Pl:time6:DL"]+2*t3*t6*vcov(CLC)["Ll:time3:DL","Ll:time6:DL"]-
      2*t4*t4*vcov(CLC)["Pl:time4:DL","Ll:time4:DL"]+2*t4*t5*vcov(CLC)["Pl:time4:DL","Pl:time5:DL"]-2*t4*t5*vcov(CLC)["Pl:time4:DL","Ll:time5:DL"]+2*t4*t6*vcov(CLC)["Pl:time4:DL","Pl:time6:DL"]-2*t4*t6*vcov(CLC)["Pl:time4:DL","Ll:time6:DL"]-
      2*t4*t5*vcov(CLC)["Ll:time4:DL","Pl:time5:DL"]+2*t4*t5*vcov(CLC)["Ll:time4:DL","Ll:time5:DL"]-2*t4*t6*vcov(CLC)["Ll:time4:DL","Pl:time6:DL"]+2*t4*t6*vcov(CLC)["Ll:time4:DL","Ll:time6:DL"]-
      2*t5*t5*vcov(CLC)["Pl:time5:DL","Ll:time5:DL"]+2*t5*t6*vcov(CLC)["Pl:time5:DL","Pl:time6:DL"]-2*t5*t6*vcov(CLC)["Pl:time5:DL","Ll:time6:DL"]-
      2*t5*t6*vcov(CLC)["Ll:time5:DL","Pl:time6:DL"]+2*t5*t6*vcov(CLC)["Ll:time5:DL","Ll:time6:DL"]-
      2*t6*t6*vcov(CLC)["Pl:time6:DL","Ll:time6:DL"]
    CI.PlLl[t,3]=CI.PlLl[t,1]-qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI lower
    CI.PlLl[t,4]=CI.PlLl[t,1]+qnorm(0.975)*sqrt(CI.PlLl[t,2])#95% CI upper
    #right:
    CI.PlLl[t,5]=CLC$coefficients["Pl_ISL"]+CLC$coefficients["Pl:time2"]*t2+CLC$coefficients["Pl:time3"]*t3+CLC$coefficients["Pl:time4"]*t4+CLC$coefficients["Pl:time5"]*t5+CLC$coefficients["Pl:time6"]*t6-
      (CLC$coefficients["Ll_ISL"]+CLC$coefficients["Ll:time2"]*t2+CLC$coefficients["Ll:time3"]*t3+CLC$coefficients["Ll:time4"]*t4+CLC$coefficients["Ll:time5"]*t5+CLC$coefficients["Ll:time6"]*t6)#fitted values
    CI.PlLl[t,6]=1*vcov(CLC)["Pl_ISL","Pl_ISL"]+t2^2*vcov(CLC)["Pl:time2","Pl:time2"]+t3^2*vcov(CLC)["Pl:time3","Pl:time3"]+t4^2*vcov(CLC)["Pl:time4","Pl:time4"]+t5^2*vcov(CLC)["Pl:time5","Pl:time5"]+t6^2*vcov(CLC)["Pl:time6","Pl:time6"]+
      1*vcov(CLC)["Ll_ISL","Ll_ISL"]+t2^2*vcov(CLC)["Ll:time2","Ll:time2"]+t3^2*vcov(CLC)["Ll:time3","Ll:time3"]+t4^2*vcov(CLC)["Ll:time4","Ll:time4"]+t5^2*vcov(CLC)["Ll:time5","Ll:time5"]+t6^2*vcov(CLC)["Ll:time6","Ll:time6"]-
      2*1*1*vcov(CLC)["Pl_ISL","Ll_ISL"]+2*1*t2*vcov(CLC)["Pl_ISL","Pl:time2"]-2*1*t2*vcov(CLC)["Pl_ISL","Ll:time2"]+2*1*t3*vcov(CLC)["Pl_ISL","Pl:time3"]-2*1*t3*vcov(CLC)["Pl_ISL","Ll:time3"]+
      2*1*t4*vcov(CLC)["Pl_ISL","Pl:time4"]-2*1*t4*vcov(CLC)["Pl_ISL","Ll:time4"]+2*1*t5*vcov(CLC)["Pl_ISL","Pl:time5"]-2*1*t5*vcov(CLC)["Pl_ISL","Ll:time5"]+2*1*t6*vcov(CLC)["Pl_ISL","Pl:time6"]-2*1*t6*vcov(CLC)["Pl_ISL","Ll:time6"]-
      2*1*t2*vcov(CLC)["Ll_ISL","Pl:time2"]+2*1*t2*vcov(CLC)["Ll_ISL","Ll:time2"]-2*1*t3*vcov(CLC)["Ll_ISL","Pl:time3"]+2*1*t3*vcov(CLC)["Ll_ISL","Ll:time3"]-
      2*1*t4*vcov(CLC)["Ll_ISL","Pl:time4"]+2*1*t4*vcov(CLC)["Ll_ISL","Ll:time4"]-2*1*t5*vcov(CLC)["Ll_ISL","Pl:time5"]+2*1*t5*vcov(CLC)["Ll_ISL","Ll:time5"]-2*1*t6*vcov(CLC)["Ll_ISL","Pl:time6"]+2*1*t6*vcov(CLC)["Ll_ISL","Ll:time6"]-
      2*t2*t2*vcov(CLC)["Pl:time2","Ll:time2"]+2*t2*t3*vcov(CLC)["Pl:time2","Pl:time3"]-2*t2*t3*vcov(CLC)["Pl:time2","Ll:time3"]+
      2*t2*t4*vcov(CLC)["Pl:time2","Pl:time4"]-2*t2*t4*vcov(CLC)["Pl:time2","Ll:time4"]+2*t2*t5*vcov(CLC)["Pl:time2","Pl:time5"]-2*t2*t5*vcov(CLC)["Pl:time2","Ll:time5"]+2*t2*t6*vcov(CLC)["Pl:time2","Pl:time6"]-2*t2*t6*vcov(CLC)["Pl:time2","Ll:time6"]-
      2*t2*t3*vcov(CLC)["Ll:time2","Pl:time3"]+2*t2*t3*vcov(CLC)["Ll:time2","Ll:time3"]-
      2*t2*t4*vcov(CLC)["Ll:time2","Pl:time4"]+2*t2*t4*vcov(CLC)["Ll:time2","Ll:time4"]-2*t2*t5*vcov(CLC)["Ll:time2","Pl:time5"]+2*t2*t5*vcov(CLC)["Ll:time2","Ll:time5"]-2*t2*t6*vcov(CLC)["Ll:time2","Pl:time6"]+2*t2*t6*vcov(CLC)["Ll:time2","Ll:time6"]-
      2*t3*t3*vcov(CLC)["Pl:time3","Ll:time3"]+
      2*t3*t4*vcov(CLC)["Pl:time3","Pl:time4"]-2*t3*t4*vcov(CLC)["Pl:time3","Ll:time4"]+2*t3*t5*vcov(CLC)["Pl:time3","Pl:time5"]-2*t3*t5*vcov(CLC)["Pl:time3","Ll:time5"]+2*t3*t6*vcov(CLC)["Pl:time3","Pl:time6"]-2*t3*t6*vcov(CLC)["Pl:time3","Ll:time6"]-
      2*t3*t4*vcov(CLC)["Ll:time3","Pl:time4"]+2*t3*t4*vcov(CLC)["Ll:time3","Ll:time4"]-2*t3*t5*vcov(CLC)["Ll:time3","Pl:time5"]+2*t3*t5*vcov(CLC)["Ll:time3","Ll:time5"]-2*t3*t6*vcov(CLC)["Ll:time3","Pl:time6"]+2*t3*t6*vcov(CLC)["Ll:time3","Ll:time6"]-
      2*t4*t4*vcov(CLC)["Pl:time4","Ll:time4"]+2*t4*t5*vcov(CLC)["Pl:time4","Pl:time5"]-2*t4*t5*vcov(CLC)["Pl:time4","Ll:time5"]+2*t4*t6*vcov(CLC)["Pl:time4","Pl:time6"]-2*t4*t6*vcov(CLC)["Pl:time4","Ll:time6"]-
      2*t4*t5*vcov(CLC)["Ll:time4","Pl:time5"]+2*t4*t5*vcov(CLC)["Ll:time4","Ll:time5"]-2*t4*t6*vcov(CLC)["Ll:time4","Pl:time6"]+2*t4*t6*vcov(CLC)["Ll:time4","Ll:time6"]-
      2*t5*t5*vcov(CLC)["Pl:time5","Ll:time5"]+2*t5*t6*vcov(CLC)["Pl:time5","Pl:time6"]-2*t5*t6*vcov(CLC)["Pl:time5","Ll:time6"]-
      2*t5*t6*vcov(CLC)["Ll:time5","Pl:time6"]+2*t5*t6*vcov(CLC)["Ll:time5","Ll:time6"]-
      2*t6*t6*vcov(CLC)["Pl:time6","Ll:time6"]
    CI.PlLl[t,7]=CI.PlLl[t,5]-qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI lower
    CI.PlLl[t,8]=CI.PlLl[t,5]+qnorm(0.975)*sqrt(CI.PlLl[t,6])#95% CI upper
  }
  CI.PlLl=as.data.frame(CI.PlLl)
  CI.PlLl$t=c(1961:2019)
  if (pe==1) {CI.PlLl=CI.PlLl[1:(10+t0),]}
  if (pe==2) {CI.PlLl=CI.PlLl[(11+t0):(20+t0),]}
  if (pe==3) {CI.PlLl=CI.PlLl[(21+t0):(30+t0),]}
  if (pe==4) {CI.PlLl=CI.PlLl[(31+t0):(40+t0),]}
  if (pe==5) {CI.PlLl=CI.PlLl[(41+t0):(50+t0),]}
  if (pe==6) {CI.PlLl=CI.PlLl[(51+t0):59,]}
  CI.PlLl
}#wo Pl:time1:DL,Ll:time1:DL

#Z-test functions:
ZtestfunT12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2)]-CLC$coefficients[paste0("Ll:time",2)]#mean
  v=vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2)]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunTD12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2,":DL")]-CLC$coefficients[paste0("Ll:time",2,":DL")]#mean
  v=vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Pl:time",2,":DL")]+vcov(CLC)[paste0("Ll:time",2,":DL"),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Ll:time",2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunD12=function(CLC){
  m=CLC$coefficients[paste0("Pl:time",2)]-CLC$coefficients[paste0("Ll:time",2)]+
    CLC$coefficients[paste0("Pl:time",2,":DL")]-CLC$coefficients[paste0("Ll:time",2,":DL")]#mean
  v=vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2)]+vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2)]+
    vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Pl:time",2,":DL")]+vcov(CLC)[paste0("Ll:time",2,":DL"),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2)]+2*vcov(CLC)[paste0("Pl:time",2),paste0("Pl:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",2),paste0("Pl:time",2,":DL")]+2*vcov(CLC)[paste0("Ll:time",2),paste0("Ll:time",2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",2,":DL"),paste0("Ll:time",2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunT=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunTD=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1,":DL")]-CLC$coefficients[paste0("Ll:time",per1,":DL")]-
        CLC$coefficients[paste0("Pl:time",per2,":DL")]+CLC$coefficients[paste0("Ll:time",per2,":DL")])#mean
  v=vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per1,":DL")]+vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per1,":DL")]+
    vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Pl:time",per2,":DL")]+vcov(CLC)[paste0("Ll:time",per2,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2,":DL")]-2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Ll:time",per2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}
ZtestfunD=function(CLC,per1,per2){
  m=-(CLC$coefficients[paste0("Pl:time",per1)]-CLC$coefficients[paste0("Ll:time",per1)]+
        CLC$coefficients[paste0("Pl:time",per1,":DL")]-CLC$coefficients[paste0("Ll:time",per1,":DL")]-
        CLC$coefficients[paste0("Pl:time",per2)]+CLC$coefficients[paste0("Ll:time",per2)]-
        CLC$coefficients[paste0("Pl:time",per2,":DL")]+CLC$coefficients[paste0("Ll:time",per2,":DL")])#mean
  v=vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1)]+vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1)]+
    vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per1,":DL")]+vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per1,":DL")]+
    vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2)]+vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2)]+
    vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Pl:time",per2,":DL")]+vcov(CLC)[paste0("Ll:time",per2,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1)]+2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per1,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2)]-2*vcov(CLC)[paste0("Pl:time",per1),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per1,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per1,":DL")]+2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2)]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Ll:time",per1),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per1,":DL")]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2)]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2)]-2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Pl:time",per1,":DL"),paste0("Ll:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2)]-
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per1,":DL"),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2)]+2*vcov(CLC)[paste0("Pl:time",per2),paste0("Pl:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Ll:time",per2),paste0("Pl:time",per2,":DL")]+
    2*vcov(CLC)[paste0("Ll:time",per2),paste0("Ll:time",per2,":DL")]-
    2*vcov(CLC)[paste0("Pl:time",per2,":DL"),paste0("Ll:time",per2,":DL")]#variance
  se=sqrt(v)#standard error
  z=m/sqrt(v)#Z score
  p=2*pnorm(-abs(z))#p-value != (two tails)
  c(m,se,p)
}

#time variables:
t0=0#starting value for thresholds (-4,-2,0,2,4)
de$time1=ifelse(de$time<=10+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time2=ifelse(de$time>10+t0&de$time<=20+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time3=ifelse(de$time>20+t0&de$time<=30+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time4=ifelse(de$time>30+t0&de$time<=40+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time5=ifelse(de$time>40+t0&de$time<=50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
de$time6=ifelse(de$time>50+t0,1,0)
```

```
## Error in de$time: object of type 'closure' is not subsettable
```

``` r
#regression:
sort(unique(de$Ey[de$DL==1]))#full coverage DL, hence full interactions
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
sort(unique(de$Ey[de$DL==0]))#full coverage non DL, hence full interactions
```

```
## Error in de$Ey: object of type 'closure' is not subsettable
```

``` r
CLC_lses103_DEU=clogit(Va ~ Pl:time2+Ll:time2+Pl:time3+Ll:time3+Pl:time4+Ll:time4+Pl:time5+Ll:time5+Pl:time6+Ll:time6+
                         Pl:time2:DL+Ll:time2:DL+Pl:time3:DL+Ll:time3:DL+Pl:time4:DL+Ll:time4:DL+Pl:time5:DL+Ll:time5:DL+Pl:time6:DL+Ll:time6:DL+
                         +Pl_AUS+Ll_AUS+Pl_AUT+Ll_AUT+Pl_CAN+Ll_CAN+Pl_DEU+Ll_DEU+Pl_DNK+Ll_DNK+Pl_ESP+Ll_ESP+Pl_FIN+Ll_FIN+Pl_GBR+Ll_GBR+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_ISR+Ll_ISR+Pl_ITA+Ll_ITA+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_NZL+Ll_NZL+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
                       +strata(Esalt), robust=T, data=de, method="efron")#regression
```

```
## Error in model.frame.default(formula = Va ~ Pl:time2 + Ll:time2 + Pl:time3 + : 'data' must be a data.frame, environment, or list
```

``` r
names(CLC_lses103_DEU$coefficients)[names(CLC_lses103_DEU$coefficients)=="time2:Ll"]="Ll:time2"
```

```
## Error: object 'CLC_lses103_DEU' not found
```

``` r
names(CLC_lses103_DEU$coefficients)[names(CLC_lses103_DEU$coefficients)=="time2:Ll:DL"]="Ll:time2:DL"
```

```
## Error: object 'CLC_lses103_DEU' not found
```

``` r
##Table F3##
#hypothesis testing:
stargazer(CLC_lses103_DEU,no.space = T,single.row = T)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
#drop low (DL==0):
ZtestfunT12(CLC_lses103_DEU)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
ZtestfunT(CLC_lses103_DEU,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
ZtestfunT(CLC_lses103_DEU,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
ZtestfunT(CLC_lses103_DEU,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
ZtestfunT(CLC_lses103_DEU,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
#drop high (DL==1):
ZtestfunD12(CLC_lses103_DEU)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
ZtestfunD(CLC_lses103_DEU,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
ZtestfunD(CLC_lses103_DEU,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
ZtestfunD(CLC_lses103_DEU,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
ZtestfunD(CLC_lses103_DEU,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
#difference in drop between high and low (DL==1 vs DL==0):
ZtestfunTD12(CLC_lses103_DEU)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
ZtestfunTD(CLC_lses103_DEU,2,3)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
ZtestfunTD(CLC_lses103_DEU,3,4)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
ZtestfunTD(CLC_lses103_DEU,4,5)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
ZtestfunTD(CLC_lses103_DEU,5,6)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_DEU' not found
```

``` r
#plots (median cty):
# tikz(paste0("plot_","CLC_lses103_DEU.tex"),width=4, height=3)
plot( ggplot() +ggtitle("") +xlab("Year") +ylab("Party/Leader Effect") + coord_cartesian(ylim=c(0.2001,0.64)) + scale_y_continuous(expand=c(0,0)) + xlim(1960,2020) +
        theme(panel.background=element_blank(), panel.grid.major=element_line(size=0.15,linetype='solid',colour = "grey"),
              panel.border=element_rect(fill="transparent",size = 0.3), text=element_text(size=12), plot.title=element_text(hjust = 0.5)) +
        geom_histogram(aes(x=Ey,y=((Eyn*(0.64-0.2001)+0.2001))),stat='identity',binwidth = 1,color="gray85",fill="gray85",data=dyALL) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses103_DEU,0,1)) +#(high)
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses103_DEU,0,2)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses103_DEU,0,3)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses103_DEU,0,4)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses103_DEU,0,5)) +
        geom_smooth(aes(x=t,y=V1,ymin=V3,ymax=V4), stat="identity", color="red", lty="44", lwd=3, CI.PlLllses10CGfun(CLC_lses103_DEU,0,6)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses103_DEU,0,1)) +#(low)
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses103_DEU,0,2)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses103_DEU,0,3)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses103_DEU,0,4)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses103_DEU,0,5)) +
        geom_smooth(aes(x=t,y=V5,ymin=V7,ymax=V8), stat="identity", color="blue", lwd=2, CI.PlLllses10CGfun(CLC_lses103_DEU,0,6)) )
```

```
## Error in eval(expr, envir, enclos): object 'dyALL' not found
```

``` r
# dev.off()


##Table I14##
##table full results:
stargazer(CLC_lses103_ea_0,CLC_lses103_LR25_0,CLC_lses103_DEU)
```

```
## Error in eval(expr, envir, enclos): object 'CLC_lses103_ea_0' not found
```

``` r
#RC DOUBLE ELECTIONS:----

##read data:
load("d29_doubleEs.RData")


##base for country-slope FE:
#Ec:Pl FE:
for (i1 in 1:length(sort(unique(dd$Ec)))) {#creating dummy variables Ec:Pl (for FE)
  dd[[paste0("Pl_",sort(unique(dd$Ec))[i1])]]=ifelse(dd$Ec==sort(unique(dd$Ec))[i1],dd$Pl,0)#dd$Pl
}
#Ec:Ll FE:
for (i1 in 1:length(sort(unique(dd$Ec)))) {#creating dummy variables Ec:Ll (for FE)
  dd[[paste0("Ll_",sort(unique(dd$Ec))[i1])]]=ifelse(dd$Ec==sort(unique(dd$Ec))[i1],dd$Ll,0)#dd$Ll
}
#create text for regression function:
txt=""
for (i1 in 1:length(sort(unique(dd$Ec)))) {#creating function text for dummy variables Es:alt except for alt=1
  txt=paste(txt,paste0("Pl_",sort(unique(dd$Ec))[i1]),sep="+")
  txt=paste(txt,paste0("Ll_",sort(unique(dd$Ec))[i1]),sep="+")
}
txt
```

```
## [1] "+Pl_DEU+Ll_DEU+Pl_FIN+Ll_FIN+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE"
```

``` r
##analyze same elections:
#Es with same national election study data (same nobs):
same_Es <- dd %>%
  group_by(Es, Ed) %>%
  summarise(n = n(), .groups = "drop") %>%
  pivot_wider(names_from = Ed, values_from = n, names_prefix = "Survey_") %>%
  filter(Survey_0 == Survey_1) %>%
  pull(Es)
#total Es:
sort(unique(dd$Es))
```

```
##  [1] "DEU_1961" "DEU_1965" "DEU_1976" "DEU_1980" "DEU_1983" "DEU_1987" "DEU_1990" "DEU_1994" "DEU_1998" "DEU_2009" "DEU_2013" "FIN_2007" "FIN_2011" "GRC_2009" "GRC_2012" "IRL_2011" "ISL_1999" "ISL_2007" "ISL_2009" "ISL_2013" "NLD_1994" "NLD_1998" "NOR_1981" "NOR_1985" "NOR_1989" "NOR_1993" "NOR_1997" "NOR_2005" "PRT_2002" "PRT_2009" "SWE_1982" "SWE_1985" "SWE_1988" "SWE_1991" "SWE_1994" "SWE_1998" "SWE_2006"
```

``` r
length(sort(unique(dd$Es)))
```

```
## [1] 37
```

``` r
#Es with same data:
same_Es
```

```
##  [1] "DEU_1961" "DEU_1965" "DEU_1976" "DEU_1980" "DEU_1983" "DEU_1987" "DEU_1990" "DEU_1994" "DEU_1998" "FIN_2011" "GRC_2009" "ISL_1999" "ISL_2007" "ISL_2009" "ISL_2013" "NLD_1998" "NOR_1981" "NOR_1985" "NOR_1989" "NOR_1993" "NOR_1997" "NOR_2005" "PRT_2002" "PRT_2009" "SWE_1991" "SWE_1994"
```

``` r
length(same_Es)
```

```
## [1] 26
```

``` r
##regressions and table:
CLC1=clogit(Va ~ Pl*Ed+Ll*Ed
            +Pl_DEU+Ll_DEU+Pl_FIN+Ll_FIN+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
            +strata(Esalt), robust=T, data=dd, method="efron")#regression
CLC2=clogit(Va ~ Pl*Ed+Ll*Ed
            +Pl_DEU+Ll_DEU+Pl_FIN+Ll_FIN+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
            +strata(Esalt), robust=T, data=dd[!(dd$Es %in% c(same_Es)),], method="efron")#regression


##regressions interaction with time:
#time variables:
t0=0#starting value for thresholds (-4,-2,0,2,4)
# de$time1=ifelse(de$time<=10+t0,1,0)
dd$time2=ifelse(dd$time>10+t0&dd$time<=20+t0,1,0)
dd$time3=ifelse(dd$time>20+t0&dd$time<=30+t0,1,0)
dd$time4=ifelse(dd$time>30+t0&dd$time<=40+t0,1,0)
dd$time5=ifelse(dd$time>40+t0&dd$time<=50+t0,1,0)
dd$time6=ifelse(dd$time>50+t0,1,0)
#regressions:
CLC3=clogit(Va ~ Pl*Ed*time+Ll*Ed*time
            +Pl_DEU+Ll_DEU+Pl_FIN+Ll_FIN+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
            +strata(Esalt), robust=T, data=dd, method="efron")#regression
CLC4=clogit(Va ~ Pl*Ed*time+Ll*Ed*time
            +Pl_DEU+Ll_DEU+Pl_FIN+Ll_FIN+Pl_GRC+Ll_GRC+Pl_IRL+Ll_IRL+Pl_ISL+Ll_ISL+Pl_NLD+Ll_NLD+Pl_NOR+Ll_NOR+Pl_PRT+Ll_PRT+Pl_SWE+Ll_SWE
            +strata(Esalt), robust=T, data=dd[!(dd$Es %in% c(same_Es)),], method="efron")#regression


##Table I1##
##table:
stargazer(CLC1,CLC3,CLC2,CLC4)
```

```
## 
## % Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
## % Date and time: Thu, Dec 04, 2025 - 11:04:11
## \begin{table}[!htbp] \centering 
##   \caption{} 
##   \label{} 
## \begin{tabular}{@{\extracolsep{5pt}}lcccc} 
## \\[-1.8ex]\hline 
## \hline \\[-1.8ex] 
##  & \multicolumn{4}{c}{\textit{Dependent variable:}} \\ 
## \cline{2-5} 
## \\[-1.8ex] & \multicolumn{2}{c}{Va} & \multicolumn{2}{c}{Va} \\ 
## \\[-1.8ex] & (1) & (2) & (3) & (4)\\ 
## \hline \\[-1.8ex] 
##  Pl & 0.705$^{***}$ & 0.696$^{***}$ & 0.678$^{***}$ & 0.675$^{***}$ \\ 
##   & (0.006) & (0.013) & (0.008) & (0.029) \\ 
##   & & & & \\ 
##  Ed & $-$0.018 & $-$0.070 & $-$0.016 & 0.004 \\ 
##   & (0.033) & (0.103) & (0.056) & (0.201) \\ 
##   & & & & \\ 
##  time &  &  &  &  \\ 
##   &  & (0.000) &  & (0.000) \\ 
##   & & & & \\ 
##  Ll & 0.033$^{***}$ & 0.037$^{***}$ & 0.039$^{***}$ & 0.061$^{***}$ \\ 
##   & (0.005) & (0.010) & (0.006) & (0.024) \\ 
##   & & & & \\ 
##  Pl\_DEU & $-$0.226$^{***}$ & $-$0.224$^{***}$ & $-$0.152$^{***}$ & $-$0.156$^{***}$ \\ 
##   & (0.008) & (0.008) & (0.014) & (0.021) \\ 
##   & & & & \\ 
##  Ll\_DEU & 0.097$^{***}$ & 0.095$^{***}$ & 0.082$^{***}$ & 0.097$^{***}$ \\ 
##   & (0.007) & (0.007) & (0.012) & (0.017) \\ 
##   & & & & \\ 
##  Pl\_FIN & $-$0.059$^{***}$ & $-$0.066$^{***}$ & $-$0.051$^{**}$ & $-$0.054$^{**}$ \\ 
##   & (0.014) & (0.015) & (0.019) & (0.023) \\ 
##   & & & & \\ 
##  Ll\_FIN & 0.014 & 0.018 & 0.040$^{**}$ & 0.051$^{***}$ \\ 
##   & (0.012) & (0.013) & (0.017) & (0.020) \\ 
##   & & & & \\ 
##  Pl\_GRC & $-$0.348$^{***}$ & $-$0.355$^{***}$ & $-$0.370$^{***}$ & $-$0.373$^{***}$ \\ 
##   & (0.013) & (0.014) & (0.016) & (0.023) \\ 
##   & & & & \\ 
##  Ll\_GRC & 0.106$^{***}$ & 0.111$^{***}$ & 0.150$^{***}$ & 0.165$^{***}$ \\ 
##   & (0.012) & (0.013) & (0.016) & (0.020) \\ 
##   & & & & \\ 
##  Pl\_IRL & $-$0.242$^{***}$ & $-$0.249$^{***}$ & $-$0.217$^{***}$ & $-$0.220$^{***}$ \\ 
##   & (0.013) & (0.015) & (0.014) & (0.021) \\ 
##   & & & & \\ 
##  Ll\_IRL & 0.039$^{***}$ & 0.044$^{***}$ & 0.034$^{***}$ & 0.048$^{***}$ \\ 
##   & (0.012) & (0.013) & (0.013) & (0.018) \\ 
##   & & & & \\ 
##  Pl\_ISL & $-$0.103$^{***}$ & $-$0.108$^{***}$ &  &  \\ 
##   & (0.010) & (0.011) & (0.000) & (0.000) \\ 
##   & & & & \\ 
##  Ll\_ISL & 0.025$^{***}$ & 0.028$^{***}$ &  &  \\ 
##   & (0.009) & (0.010) & (0.000) & (0.000) \\ 
##   & & & & \\ 
##  Pl\_NLD & $-$0.117$^{***}$ & $-$0.119$^{***}$ & $-$0.086$^{***}$ & $-$0.086$^{***}$ \\ 
##   & (0.012) & (0.012) & (0.017) & (0.017) \\ 
##   & & & & \\ 
##  Ll\_NLD & 0.037$^{***}$ & 0.038$^{***}$ & $-$0.0005 & 0.002 \\ 
##   & (0.011) & (0.011) & (0.015) & (0.015) \\ 
##   & & & & \\ 
##  Pl\_NOR & $-$0.012 & $-$0.012 &  &  \\ 
##   & (0.008) & (0.008) & (0.000) & (0.000) \\ 
##   & & & & \\ 
##  Ll\_NOR & 0.038$^{***}$ & 0.039$^{***}$ &  &  \\ 
##   & (0.007) & (0.007) & (0.000) & (0.000) \\ 
##   & & & & \\ 
##  Pl\_PRT & $-$0.372$^{***}$ & $-$0.377$^{***}$ &  &  \\ 
##   & (0.013) & (0.013) & (0.000) & (0.000) \\ 
##   & & & & \\ 
##  Ll\_PRT & 0.108$^{***}$ & 0.111$^{***}$ &  &  \\ 
##   & (0.011) & (0.012) & (0.000) & (0.000) \\ 
##   & & & & \\ 
##  Pl\_SWE &  &  &  &  \\ 
##   & (0.000) & (0.000) & (0.000) & (0.000) \\ 
##   & & & & \\ 
##  Ll\_SWE &  &  &  &  \\ 
##   & (0.000) & (0.000) & (0.000) & (0.000) \\ 
##   & & & & \\ 
##  Pl:Ed & 0.004 & $-$0.0003 & 0.007 & 0.003 \\ 
##   & (0.005) & (0.015) & (0.009) & (0.032) \\ 
##   & & & & \\ 
##  Pl:time &  & 0.0003 &  & 0.0001 \\ 
##   &  & (0.0003) &  & (0.001) \\ 
##   & & & & \\ 
##  Ed:time &  & 0.001 &  & $-$0.001 \\ 
##   &  & (0.003) &  & (0.005) \\ 
##   & & & & \\ 
##  Ed:Ll & $-$0.001 & 0.006 & $-$0.003 & $-$0.005 \\ 
##   & (0.004) & (0.012) & (0.008) & (0.027) \\ 
##   & & & & \\ 
##  time:Ll &  & $-$0.0001 &  & $-$0.001 \\ 
##   &  & (0.0003) &  & (0.001) \\ 
##   & & & & \\ 
##  Pl:Ed:time &  & 0.0001 &  & 0.0001 \\ 
##   &  & (0.0004) &  & (0.001) \\ 
##   & & & & \\ 
##  Ed:time:Ll &  & $-$0.0002 &  & 0.0001 \\ 
##   &  & (0.0003) &  & (0.001) \\ 
##   & & & & \\ 
## \hline \\[-1.8ex] 
## Observations & 468,144 & 468,144 & 157,203 & 157,203 \\ 
## R$^{2}$ & 0.281 & 0.281 & 0.280 & 0.280 \\ 
## Max. Possible R$^{2}$ & 0.949 & 0.949 & 0.949 & 0.949 \\ 
## Log Likelihood & $-$621,155.700 & $-$621,153.700 & $-$208,273.700 & $-$208,272.200 \\ 
## Wald Test & 125,498.800$^{***}$ (df = 21) & 125,554.500$^{***}$ (df = 26) & 38,822.260$^{***}$ (df = 15) & 38,875.380$^{***}$ (df = 20) \\ 
## LR Test & 154,403.600$^{***}$ (df = 21) & 154,407.700$^{***}$ (df = 26) & 51,722.250$^{***}$ (df = 15) & 51,725.140$^{***}$ (df = 20) \\ 
## Score (Logrank) Test & 127,069.800$^{***}$ (df = 21) & 127,358.200$^{***}$ (df = 26) & 42,317.870$^{***}$ (df = 15) & 42,398.140$^{***}$ (df = 20) \\ 
## \hline 
## \hline \\[-1.8ex] 
## \textit{Note:}  & \multicolumn{4}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
## \end{tabular} 
## \end{table}
```

